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

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
old/ old/
manual.odt manual.odt
mwe mwe
centos-upgrade-plan.txt

View File

@@ -40,10 +40,10 @@ if [[ -d /mnt/array/home-retired/$username ]]; then
fi fi
samba="no" samba="no"
ask_ok "Enable shared file access for user $username?" && group_str="smbgrp" && samba="yes" ask_ok "Enable shared file access for user $username?" && group_str="smbgrp," && samba="yes"
ask_ok "Make $username an admin?" && \ ask_ok "Make $username an admin?" && \
group_str+=",wheel" group_str+="wheel"
useradd_cmd+=("-G" "$group_str") useradd_cmd+=("-G" "$group_str")
useradd_cmd+=("$username") useradd_cmd+=("$username")
@@ -64,6 +64,9 @@ if [[ "$samba" == "yes" ]]; then
(echo "$password"; echo "$password") | smbpasswd -a -s "$username" (echo "$password"; echo "$password") | smbpasswd -a -s "$username"
fi fi
ask_ok "Prompt user to reset password on next login?" &&
sudo passwd --expire "$username"
# TODO check if centos 9 does by default # TODO check if centos 9 does by default
# Add subuids & subgids for container namespace # Add subuids & subgids for container namespace
# id_offset=100000 # id_offset=100000

View File

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