Skip to content

Instantly share code, notes, and snippets.

@rpetit3
Last active November 15, 2023 18:25
Show Gist options
  • Select an option

  • Save rpetit3/8ad5f1bdc7bce74919098590833dfec4 to your computer and use it in GitHub Desktop.

Select an option

Save rpetit3/8ad5f1bdc7bce74919098590833dfec4 to your computer and use it in GitHub Desktop.
reset-password - simple script to reset password of user in Debian
#! /bin/bash
if [[ $# == 0 ]]; then
echo ""
echo "reset-password NEW_USERNAME"
echo ""
echo "Example Command"
echo "reset-password robert_petit"
echo ""
exit
fi
USERNAME=$1
PASSWORD=$(head /dev/urandom | md5sum | cut -c1-10)
# Reset password
usermod --password $(echo ${PASSWORD} | openssl passwd -1 -stdin) ${USERNAME}
# set password to expire on first login
chage -d 0 ${USERNAME}
echo "Username: ${USERNAME}"
echo "New One-Time Password: ${PASSWORD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment