Alpha
This commit is contained in:
32
script-user-reset-password
Executable file
32
script-user-reset-password
Executable 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 $?
|
||||
Reference in New Issue
Block a user