Change user password through BASH script

Published on Author gryzliLeave a comment

Very often I need to automate some bulk user password change.

In the following examples we have:

$user as username

$pass as password in plain text

Currently these are the methods I use to change user passwords:

chpasswd method

echo "$user:$pass" | chpasswd

The old passwd method

echo -e "$pass\n$pass" | passwd $user

 

Also I use the following to GENERATE RANDOM passwords:

The good /dev/urandom

head /dev/urandom | md5sum | awk {'print $1'}

Using pwgen

# This will generate 20 chars long password
# For more info check pwgen manpage
pwgen -c -y 20

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *