45 lines
915 B
Bash
Executable File
45 lines
915 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Reset a user password on the server
|
|
# Copyright 2021-2025 Bryan C. Roessler
|
|
# Licensed under the Apache License, Version 2.0
|
|
p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1
|
|
|
|
is_root
|
|
|
|
echo "Usage: $0 [username] [password]"
|
|
|
|
case $# in
|
|
0)
|
|
prompt user
|
|
prompt password
|
|
;;
|
|
1)
|
|
user="$1"
|
|
prompt password
|
|
;;
|
|
2)
|
|
user="$1"
|
|
password="$2"
|
|
;;
|
|
*)
|
|
echo "Too many arguments provided"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
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
|