Last active
March 21, 2020 01:06
-
-
Save jacksonporter/1bd7292cd5da603729b09424ca5df752 to your computer and use it in GitHub Desktop.
Removes a user and their home directory as well as deleting any mention of their name in the sudoers file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
eval "$(curl -fsSL https://gist.github.com/jacksonporter/791145218e977ef9165abd9fdf8fbfd4/raw)" # obtains my common bash utilies script and "sources" it | |
check_if_root | |
read -p "Enter a username: " USERNAME | |
if [ "${USERNAME}" == "" ]; then | |
print_error "You did not enter a user name." | |
exit 1 | |
fi | |
deluser ${USERNAME} && rm -rf /home/${USERNAME} | |
grep -v "${USERNAME}" /etc/sudoers > /tmp/sds && sudo visudo -c -f /tmp/sds | |
chown root:root /tmp/sds | |
chmod 0440 /tmp/sds | |
cp /tmp/sds /etc/sudoers | |
rm -rf /tmp/sds |
How to run easily:
curl -fsSL https://gist.github.com/jacksonporter/1bd7292cd5da603729b09424ca5df752/raw > "./remove_user.sh" && sudo bash "./remove_user.sh" && rm "./remove_user.sh"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Careful! This is a dangerous script. The
awk
command will delete an entire line from the sudoers file that contains the specified username.