Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Just wondering if it's possible to pass the password I want to use to the adduser command in ubuntu, so that it can be automated.

I want to do something like this

echo "password" | adduser test

This would eliminate the need to fill out the form needed for the adduser command and set the password, "password", for the "test" user.

share|improve this question
    
linux.die.net/man/8/chpasswd –  Zoredache Jun 27 '11 at 21:24
add comment

1 Answer

You cannot do this with the adduser command, however you can with the underlying useradd command, if you have the crypted version of the password:

useradd <username> -p <crypted password>

You will likely want to include other options on the useradd command line, to set up groups, etc. Read the useradd(8) man page for details.

You could also do this with usermod, after having used adduser to initially create the account, if that's easier for you.

share|improve this answer
    
Thanks! But how how do I encrypt the password to linux specifications? –  Flashuni Jun 27 '11 at 20:05
    
The usradd(8) man page tells you: "The encrypted password, as returned by crypt(3)." Most systems have the 'crypt' command installed which will output the format you need. –  Flimzy Jun 27 '11 at 20:09
    
you can get other details on encryption by running man passwd . –  thinice Jun 27 '11 at 22:00
    
Not to be pedantic or anything, but Ubuntu systems use hashing and not encryption to securely store passwords. It may seem like a silly distinction, especially when we are talking about cryptographically secure hashes, but if you intend to do any security work at all, it will trip you up down the road. Cryptography goes two ways. Hashes only go one way. –  Slartibartfast Jun 28 '11 at 5:29
    
You need to argue that with the author of the useradd man page--all Unix systems do that. crypt always outputs a hash. –  Flimzy Jun 28 '11 at 5:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.