MD5 encryption with "useradd" command

Hi,

I have Linux 7.1 installed with MD5 enabled.
when I type:
$> useradd -g popusers -p THEPASS USERNAME

The user USERNAME is created. But The /etc/shadow file contains THEPASS as I typed it (Not encrypted)!!!

I would like to have the passwords from command line automatically MD5 incrypted without using the passwd utility.

Thanks
CurieuxAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jlevieConnect With a Mentor Commented:
As pointed out, the useradd command requires that you specify the encrypted password (MD5 in this case). An easy way to generate such a password is with a small Perl script. To use it you'll need to get and install the Crypt::PasswdMD5 module.

Save what's below into a file named md5passwd, make it executable (chmod +x md5passwd) and execute it with ./md5passwd <your-passwd>. The result will be printed on STDOUT.

#!/usr/bin/perl
#
# NAME
#       md5passwd - generate an MD5 encrypted password
#
# SYNOPSIS
#       md5passwd password
#
# DESCRPTION
#       Encrypts the specified password with MD5 in a manner suitable for use
#       in a Linux passwd/shadow file.
#
#       This code requires the CPAN Crypt-PasswdMD5-1.2.tar.gz (or later) Perl
#       module to be installed, which you can get from http://www.perl.com/CPAN
#
# Author: Jim Levie (jim@entrophy-free.net)
#
use Crypt::PasswdMD5;

if($#ARGV != 0)
{
  print "usage - md5passwd password\n\n";
  exit(1);
}

@range = (qw(. /), '0'..'9','a'..'z','A'..'Z');

$salt = join '', map $range[rand $x], 1..shift||1;

$epw = unix_md5_crypt($pw, $salt);
print "$epw\n";
exit(0);
0
 
arvindCommented:
Only passwd command can encrypt the text to MD5. I think u need use passwd for password. By the way why you like to give passwd in the useradd command. Ar u want to create bulk users?
0
 
cincin77Commented:
by using the -p option of useradd, you mean that the encrypted state of the password is what you write.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ahoffmannCommented:
listening ..
0
 
CleanupPingCommented:
Curieux:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
cincin77Commented:
I do agree with my comment...
0
 
paullamhkgCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: jlevie {http:#7155163}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

paullamhkg
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.