February 16, 2012

157 words 1 min read

Non-interactive (Unattended) password change under Ubuntu

Last night I had programmatically created a large number of users on a server. Today, I started getting emails from the users complaining that their new accounts didn’t work. Turns out my user creation script had not set their passwords correctly, so I needed to reset everyone’s password. Try as I might, I could not find an automagic method to do so with passwd; thankfully, it turns out there is another command to use for this.

With a bit of kicking around on google I found a

Linux forum post with a solution that actually worked under Ubuntu. Use chpasswd.

echo 'username:password'|chpasswd

Of course replace username and password with the proper values. You can either wrap this in a batch script, or utilize my method and build a command list in a Google Docs Spreadsheet (or Excel) to copy and paste en-mass. A few seconds later, everyone’s password was reset and I went back to reading reddit.