reset linux password email user script

December 1, 2011

this script will reset a user’s password and email it to them.

It accepts two parameters (username) (email address)

Example Usage:
./ someuser [email protected]

if [ $# -ne 2 ]; then echo "Please provide a username and email address"; exit 0; fi
TMP_PASSWORD=$(openssl rand -base64 6)
echo "Resetting Password for $1"
echo $TMP_PASSWORD | /usr/bin/passwd --stdin $1
if [ $? != 0 ]; then exit 1; fi
echo 'Password reset.'
echo Sending notification email to $2

printf "To:$2\nFrom:Admin \nSubject:Your Account\nI reset your password for you.\n\nThe username is: $1\nThe password is: $TMP_PASSWORD\n\nPlease contact [email protected] with any questions.\n\nThank you,\n\nThe Administrator\n" | /usr/sbin/sendmail -t

echo 'Done.'