Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 – Zoredache Jun 27 '11 at 21:24

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

Your Answer


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.