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.

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
2  
check this: stackoverflow.com/questions/714915/… –  Paul Mar 26 '11 at 16:36

2 Answers 2

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

 
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.