-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm_user.sh
executable file
·36 lines (29 loc) · 951 Bytes
/
rm_user.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Check if the script is being run with superuser privileges
if [[ $EUID -ne 0 ]]; then
echo "This script must be run with superuser privileges. Exiting."
exit 1
fi
echo "Welcome to the user removal script!"
read -p "Please enter the username of the user you want to remove: " username
# Check if the user exists
if id "$username" &>/dev/null; then
echo "User '$username' exists. Proceeding with removal..."
else
echo "User '$username' does not exist. Exiting."
exit 1
fi
# Check if the user to be removed is the current user
if [[ "$username" == "$(whoami)" ]]; then
echo "Removing the current user is not allowed. Exiting."
exit 1
fi
# Remove the user and their home directory
sudo userdel -r "$username"
# Check if the user was successfully removed
if id "$username" &>/dev/null; then
echo "Failed to remove user '$username'."
exit 1
else
echo "User '$username' has been removed successfully."
fi