1

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?

Billy
  • 15
  • 1
  • 4
  • 2
    check this: http://stackoverflow.com/questions/714915/using-the-passwd-command-from-within-a-shell-script – Paul Mar 26 '11 at 16:36

2 Answers2

1

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

1

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.

Bittrance
  • 2,970
  • 2
  • 21
  • 27