SSH.sh: Improve output when disabling ssh users

Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
This commit is contained in:
Tobias Knöppler 2023-04-05 21:45:07 +02:00
parent fd60a22b17
commit 18058ed366
No known key found for this signature in database
GPG Key ID: 3510056072886A8F

View File

@ -41,7 +41,7 @@ configure()
# --force: exit successfully if the group already exists
groupadd --force ncp-ssh
# Change or create credentials
if id "$USER" &>/dev/null
then
@ -57,10 +57,10 @@ configure()
useradd --create-home --home-dir /home/"$USER" --shell /bin/bash --groups ncp-ssh "$USER" || return 1
echo -e "$PASS\n$CONFIRM" | passwd "$USER" || return 1
fi
# Get the current users of the group to an array
mapfile -d ',' -t GROUP_USERS < <(awk -F':' '/ncp-ssh/{printf $4}' /etc/group)
if [[ "${#GROUP_USERS[@]}" -gt 0 ]]
then
# Loop through each user in the group
@ -69,6 +69,7 @@ configure()
# Test if extra users exists in the group
if [[ "$U" != "$USER" ]]
then
echo "Disabling user '$U'..."
# Locks any extra accounts
usermod --lock --expiredate 1 "$U"
fi
@ -77,7 +78,7 @@ configure()
# Unsets the group array variable (cleanup)
unset GROUP_USERS
[[ "$SUDO" == "yes" ]] && {
usermod --append --groups sudo "$USER"
echo "Enabled sudo for $USER"