Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

3 Answers 3

up vote 7 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 at 19:34
man page for openssl passwd is here: – ryenus Jun 30 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.