1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #!/usr/bin/env bash
- # This script will reset a user password on the server
- # Copyright 2021-24 Bryan C. Roessler
- unset user password
- parent="${BASH_SOURCE[0]}"
- parent=${parent%/*}
- [[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
- is_root
- echo "This script supports two optional arguments, a username and password"
- if [[ $# -eq 0 ]]; then
- prompt user
- prompt password
- elif [[ $# -eq 1 ]]; then
- user="$1"
- prompt password
- elif [[ $# -eq 2 ]]; then
- user="$1"
- password="$2"
- elif [[ $# -gt 2 ]]; then
- echo "Too many arguments provided"
- exit 1
- fi
- if ! id -u "$user" &>/dev/null; then
- echo "User $user does not exist"
- exit 1
- fi
- if ask_ok "Change user $user's password to $password?"; then
- echo "$user":"$password" | chpasswd
- (echo "$password"; echo "$password") | smbpasswd -a -s "$user"
- fi
- ask_ok "Prompt user to reset password on next login?" &&
- passwd --expire "$user" &&
- echo "NOTE: The file sharing (smbpasswd) will not be changed"
-
- exit 0
|