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

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>