[Gllug] passwd and creating passwords

Jason Clifford jason at ukpost.com
Tue Jan 27 16:44:18 UTC 2004


On Tue, 27 Jan 2004, Xander D Harkness wrote:

> I would like to add a user using useradd -p hashed-password joe
> 
> useradd can take a password on the command line but it needs to be a 
> hash ready to be placed in the /etc/shadow file.
> 
> How can I create the correct md5 hash as none of the man pages are very 
> helpful.

The following perl will do it for you:

my $salt = '$1$';
$salt .= join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64, 
         rand 64, rand 64, rand 64, rand 64, rand 64, rand 64];
my $pwcrypt = crypt($password, $salt);

They key thing to note is that the salt is $1$ followed by 8 more slat 
characters. I think the standard crypt call will recognise that throughout 
a suitable system and return an MD5 hash.

The easiest route is likely to be copy and paste the above perl into a 
little script file and use that.

Jason Clifford
-- 
UKFSN.ORG		Finance Free Software while you surf the 'net
http://www.ukfsn.org/	   ADSL Broadband from just £23.75 / month 

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list