Don't expire user password on reset
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
old/
|
||||
manual.odt
|
||||
mwe
|
||||
mwe
|
||||
centos-upgrade-plan.txt
|
||||
|
||||
@@ -40,10 +40,10 @@ if [[ -d /mnt/array/home-retired/$username ]]; then
|
||||
fi
|
||||
|
||||
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?" && \
|
||||
group_str+=",wheel"
|
||||
group_str+="wheel"
|
||||
|
||||
useradd_cmd+=("-G" "$group_str")
|
||||
useradd_cmd+=("$username")
|
||||
@@ -64,6 +64,9 @@ if [[ "$samba" == "yes" ]]; then
|
||||
(echo "$password"; echo "$password") | smbpasswd -a -s "$username"
|
||||
fi
|
||||
|
||||
ask_ok "Prompt user to reset password on next login?" &&
|
||||
sudo passwd --expire "$username"
|
||||
|
||||
# TODO check if centos 9 does by default
|
||||
# Add subuids & subgids for container namespace
|
||||
# id_offset=100000
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user