Linux – Pass password to adduser command

bashcommand-line-interfacelinuxUbuntuuseradd

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.

Best 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.