Solved

MD5 encryption with "useradd" command

Posted on 2002-07-12
8
1,253 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
ID: 7151065
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
ID: 7153724
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
ID: 7155163
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7155747
listening ..
0
 

Expert Comment

by:CleanupPing
ID: 9078459
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
ID: 9078484
I do agree with my comment...
0
 
LVL 12

Expert Comment

by:paullamhkg
ID: 10020057
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

809 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