useradd command

choccarlm
choccarlm used Ask the Experts™
on
Hi,

I need to be able to run the "useradd" command via a script, but the problem is, is that the password doesnt get set properly using the -p option. When I run the following command

useradd -s /bin/false -p 1234 test

It adds the user, but the password in /etc/shadow isnt encrypted, it appears as "1234", and I cant logon via ftp or pop3 using this account until I manually set the password.

Is there any way I can set this password correctly using the useradd command in a shell script?

Cheers
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I've just found that the following commands work:

useradd -s /bin/false -p <password> <login>
echo "<password>" | passwd --stdin <login>

But is this the only way of getting it to work?
Top Expert 2005
Commented:
The -p argument to useradd expect the password to be an encrypted string (DES or MD5, depending on local configuration). There's not a command line utility to generate an encrypted string from a password, so the way you are doing it is the only native way. It is possible to write a program or perl/python script which will generate the encrypted form of the password, but that's not any easier to do in a script than what you are doing now.

Author

Commented:
Ok, thanks.

Shall I delete the question, or is awarding the points to yourself the done thing?
Top Expert 2005

Commented:
What to do with the question is up to you. Although you didn't realize it at the time, you had found the answer before I commented on the question. It doesn't matter to me whether you delete the question or accept the comment as the answer.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial