reset linux password email user script

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

It accepts two parameters (username) (email address)

Example Usage:
./reset_user_password.sh someuser [email protected]


#!/usr/local/bin/bash
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.'

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.