Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 am writing a script to add a large amount of users to a system. Part of this involves setting default passwords for each user. How can I set users' passwords without it prompting me for the password up front?

Unfortunately passwd doesn't seem to take an argument stating the new password to set. I'm using Ubuntu 11.10.

share|improve this question
up vote 8 down vote accepted

Try usermod:

usermod --password PASSWORD USERNAME

The only thing is this needs a pre-encrypted password string which you'd have to generate first.

share|improve this answer
...which I can generate using mkpasswd. Excellent, thanks! – Jake Petroules Nov 18 '11 at 11:27
You can also use openssl to generate the encrypted password. For example: usermod --password $(echo my_new_password | openssl passwd -1 -stdin) USERNAME – Eric Smith Jan 16 '15 at 19:34
man page for openssl passwd is here: – ryenus Jun 30 '15 at 4:02

You should look at the chpasswd command (if available in your linux flavor):

echo 'userid:newpasswd' | chpasswd

Or, you can cat a file listing userid:passwd for each account on a separate line.

That's it.

share|improve this answer

You should use password aging, and set the users so that they must change their password on the first login. See this article.

share|improve this answer
These intended to be FTP-only accounts, but good advice. ;) – Jake Petroules Nov 18 '11 at 22:49

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.