Monday, November 2, 2015

Bulk update passwords

Shell script to update passwords for multiple users all at once.

Create a file with the list of account user names:

$ vim names.txt

user1
user2
user3

Create a script which will go through each username and execute the password update:

$ vim userupdate.sh

#!/bin/bash

for i in `cat names.txt`
do
  echo $i
  # set password to 123 for each user
  echo $i"123" | passwd –-stdin "$i"
  # for reset password at first login
  chage -d 0 $i
done

Run the script:

$ chmod +x userupdate.sh

$ sudo userupdate.sh

This script was partially inspired by a how-to-forge article.