Solved

MD5 encryption with "useradd" command

Posted on 2002-07-12
8
1,245 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:Curieux
8 Comments
 
LVL 5

Expert Comment

by:arvind
Comment Utility
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
 
LVL 3

Expert Comment

by:cincin77
Comment Utility
by using the -p option of useradd, you mean that the encrypted state of the password is what you write.
0
 
LVL 40

Accepted Solution

by:
jlevie earned 50 total points
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
listening ..
0
 

Expert Comment

by:CleanupPing
Comment Utility
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
 
LVL 3

Expert Comment

by:cincin77
Comment Utility
I do agree with my comment...
0
 
LVL 12

Expert Comment

by:paullamhkg
Comment Utility
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now