From e45b89c5827b0f6b6fa17f4d1faadaf3a51c28cb Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 6 Jan 2025 13:45:51 +0900 Subject: [PATCH] AWS Delete user, remove all secondary groups first. To make sure tha on delete the user is removed from all secondary groups unset them first before running the userdel command. -r might not be enought to do that in some situations --- bin/delete_user.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/delete_user.sh b/bin/delete_user.sh index 52d5bbb..8a06ee5 100755 --- a/bin/delete_user.sh +++ b/bin/delete_user.sh @@ -164,9 +164,13 @@ for username in "$@"; do echo "[1] Remove user + home dir"; if [ ${TEST} -eq 0 ]; then - userdel -r "${username}" + # remove all secondary group entries first before we delete the user + # there might be cases where they are left + usermod -G "" "${username}"; + userdel -r "${username}"; else - echo "$> userdel -r ${username}"; + echo "$> usermod -G \"\" \"${username}\""; + echo "$> userdel -r \"${username}\""; fi; # remove ssh files in pub