Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-27-2009, 03:12 PM   #1
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
Creating password hash.


I need to create password hash. Reason I need it so I can use it to create user account with one line "useradd" command.
Some thing like this.

#useradd username -p <hash>

What I have found out is

is different as it use to be ??
What I found on the Internet makepasswd seems like it has what I need.


makepasswd(1)                UNIX Reference Manual               makepasswd(1)

       makepasswd - generate and/or encrypt passwords

       makepasswd [ --chars N ] [ --clearfrom file ] [ --count N ] [ --crypt |
       --nocrypt | --crypt-md5 ] [ --cryptsalt N ] [ --help ] [ --maxchars N ]
       [ --minchars N ] [ --randomseed N ] [ --rerandom N ] [ --repeatpass N ]
       [ --string string ] [ --verbose | --noverbose ]

       makepasswd generates true random passwords  by  using  the  /dev/random
       feature  of Linux, with the emphasis on security over pronounceability.
       It can also encrypt plaintext passwords given on the command line.

       --chars N
              Generate passwords with exactly N characters (do  not  use  with
              options --minchars and --maxchars).

       --clearfrom FILE
              Use   password   from  FILE  instead  of  generating  passwords.
              Requires the --crypt or the --crypt-md5 options; may not be used
              with  these  options:  --chars, --maxchars, --minchars, --count,
              --string, --nocrypt.  Trailing newlines are  removed  but  other
              white space is not.

       --count N
              Produce a total of N passwords (the default is one).

              Produce encrypted passwords.

              Produce  encrypted  passwords  using the MD5 digest (hash) algo-


But I was only able to find makepasswd from Afetr installing it what I have is

$ makepasswd --help
Usage: makepasswd [option [value]] ...
	-c, --chars	string of allowed characters (A..Za..z0..9)
	-e, --encrypt	encryption algorithm {none,des,md5,shmd5} (none)
	-l, --length	password length
	-M, --max	password maximum length (8)
	-m, --min	password minimum length (8)
	-n, --number	number of passwords to generate (1)
	-p, --password	password to use
	-s, --salt	salt to use (random)
	-h, --help	display this help screen
	-V, --version	display program version
Its not the same utility.

Any suggestion about,

1-where to find real makepasswd.
2-If not, how do I get password hash exactly the way it looks in "/etc/shadow" file.


Last edited by knockout_artist; 10-27-2009 at 03:13 PM.
Old 10-27-2009, 03:27 PM   #2
LQ Newbie
Registered: Aug 2009
Location: Calgary, AB
Posts: 2

Rep: Reputation: 0
In RedHat I accomplish the scripting of user passwords in the following way (with an externally generated password as $pass):

echo $pass | sudo passwd --stdin $username > /dev/null

Hope this helps

Old 11-02-2009, 11:27 PM   #3
LQ Newbie
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
I have the same problem. In my case I'm trying to generate password hashes that are suitable for Unix when a user logs into a web portal, but I don't want to create local accounts.
Old 11-03-2009, 12:33 AM   #4
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182Reputation: 3182
Commands like useradd will generate appropriately hashed password-values where and when they are needed. You don't supply the hashed values yourself.

Hashed passwords are normally calculated using algorithms such as sha1 or (less commonly these days) md5. Functions to produce them are readily available in whatever is your language of choice.
Old 11-04-2009, 07:49 AM   #5
LQ Newbie
Registered: Nov 2009
Posts: 2

Rep: Reputation: 0
useradd doesn't really work as that does local account management. Think a web portal where a user creates an account and as they are granted privileges accounts are created for them on various machines. For security reasons you don't want to keep their password around, instead you want to create the appropriate password hashes that you might need later. Generic MD5 doesn't work b/c the password hash is salted and has some other odd bits done to it. I managed to find a perl module that would generate it for me so I'm good.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
password hash evil_empire Linux - Security 4 04-25-2009 08:16 AM
Restoring Password Hash zok Linux - Server 3 04-29-2008 01:22 PM
What type of password hash is this ? memo007 Linux - Security 7 12-26-2007 03:34 AM
Password Hash Query aml1973 Linux - Security 1 12-03-2007 08:50 AM
Change Password Hash Algorithm Trano Linux - Security 1 08-23-2005 08:48 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration