Don't expire user password on reset

This commit is contained in:
2024-06-30 15:22:01 -04:00
parent cf7245833a
commit ccf91fe0f5
3 changed files with 20 additions and 17 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# This script will reset a user password on the server
# Copyright 2021 Bryan C. Roessler
# Copyright 2021-24 Bryan C. Roessler
unset user password
@@ -11,29 +11,28 @@ parent=${parent%/*}
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"
if [[ $# -eq 0 ]]; then
prompt username
prompt password
elif [[ $# -eq 1 ]]; then
username="$1"
prompt password
elif [[ $# -eq 2 ]]; then
username="$1"
password="$2"
elif [[ $# -gt 2 ]]; then
echo "Too many arguments provided"
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
if ! id -u "$username" &>/dev/null; then
echo "User $user does not exist"
exit 1
fi
password="${password:-$user}"
if ask_ok "Change user $user's password to $password?"; then
echo "$user":"$password" | chpasswd
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
passwd --expire "$user"
fi
exit 0