The man page for useradd says


-p, --password PASSWORD The encrypted password, as returned by crypt(3). The default is to disable the password. Note: This option is not recommended because the password (or encrypted password) will be visible by users listing the processes.

You should make sure the password respects the system's password policy.

But there doesn't seem to be any other way to create an account. Also, it says the default is to disable the password - what does that mean?

I am using Debian Wheezy


taken from this script https://gist.github.com/Fluidbyte/6321547

There's a great language called expect that interacts with programs. Here's what you're looking for. You can always modify this to pull username and password from an external source.


set user "username"
set password "password"

send "useradd -m $user\r"

# Expect prompt
expect "$"

# Set password
send "passwd $user\r"

# Expect password prompt and send pass
expect "ass"
send "$password\r"

# Expect confirm
expect "ass"
send "$password\r"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.