Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I need to create a user with password in a shell script, but passwd wants me to enter the password twice. Is there a way to create a user with password in one command?

share|improve this question
check this:… – Paul Mar 26 '11 at 16:36
up vote 1 down vote accepted

You can use this command.

echo -e "password\password\n\n\n\n\n\n\n\n"|adduser username

Please replace the 'password' with the desired password and 'username' with the username you need to create.

Regards, Ajo

share|improve this answer
Works perfectly... thank you very much – Billy Mar 26 '11 at 16:51

If you want to create a user in a shell script, you should use useradd -p which takes the encrypted form of the password. That way, you don't have have the password in cleartext.

Note that on debian, users are normally added with adduser, which has various bits of policy configured in /etc/adduser.conf. useradd is the "raw" command, so you need to take care to get group membership and homedir permissiones as you expect them.

share|improve this answer

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.