Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 3 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 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

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

Your Answer

 
discard

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.