42 lines
989 B
Bash
Executable File
42 lines
989 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# This script will reset a user password on the server
|
|
# Copyright 2021 Bryan C. Roessler
|
|
|
|
unset user password
|
|
|
|
parent="${BASH_SOURCE[0]}"
|
|
parent=${parent%/*}
|
|
|
|
[[ -f "$parent"/functions ]] && . "$parent"/functions || exit 1
|
|
|
|
is_root
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
echo "Current users: "
|
|
eval "getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1"
|
|
exit 1
|
|
fi
|
|
|
|
[[ $# -ge 1 ]] && user="$1"
|
|
|
|
[[ $# -eq 2 ]] && password="$2"
|
|
|
|
[[ $# -gt 2 ]] && "Too many arguments" && exit 1
|
|
|
|
if ! id -u "$user" &>/dev/null; then
|
|
echo "User $user does not exist"
|
|
exit 1
|
|
fi
|
|
|
|
password="${password:-$user}" # For samba
|
|
|
|
ask_ok "Change user $user's password to $password?" || exit
|
|
echo "$user":"$password" | chpasswd
|
|
echo "Expiring user password"
|
|
passwd --expire "$user"
|
|
|
|
ask_ok "Change user $user's Samba password to $password?" || exit
|
|
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
|
|
|
|
exit $?
|