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:
./ 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.'

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

You can use these HTML tags

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