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.

2 comments:

  1. Heu?

    `passwd` does not seem to have this --stdin option on Ubuntu 16.04, I even checked the man page....

    Maybe you meant `mkpasswd` from the `whois` package ?

    ReplyDelete
  2. Merci pour le commentaire. ;-)

    This may not exist on Ubuntu, but it is a parameter in RedHat's passwd command option. =)


    https://linux.die.net/man/1/passwd

    ReplyDelete