Last active
November 15, 2023 18:25
-
-
Save rpetit3/8ad5f1bdc7bce74919098590833dfec4 to your computer and use it in GitHub Desktop.
reset-password - simple script to reset password of user in Debian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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