This commit is contained in:
2021-10-19 16:36:21 -04:00
parent 8dbb3d0bb3
commit 64f6c11503
8 changed files with 448 additions and 33 deletions

32
script-user-reset-password Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# This script will reset a user password on the server
# Copyright 2021 Bryan C. Roessler
[[ -f functions ]] && . functions || exit 1
is_root
[[ $? -lt 1 ]] && echo "Must provide a username" && exit 1
[[ $? -gt 1 ]] && user="$1"
[[ $? -eq 2 ]] && password="$2"
[[ $? -gt 2 ]] && "Too many arguments" && exit 1
id -u "$user" || echo "User $user does not exist" && exit 1
if [[ "$password" == "reset" ]]; then
ask_ok "Reset user $user's password?" || return $?
passwd --expire "$user"
password="$user" # For samba
else
ask_ok "Change user $user's password to $password?" && \
echo "$user":"$password" | chpasswd
fi
ask_ok "Change user $user's Samba ppassword to $password?" && \
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
exit $?