32 lines
642 B
Bash
Executable File
32 lines
642 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Usage: ./remove_samba_user.sh <username>
|
|
|
|
# Check for root
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script must be run as root."
|
|
exit 1
|
|
fi
|
|
|
|
USERNAME="$1"
|
|
|
|
if [[ -z "$USERNAME" ]]; then
|
|
read -p "Enter username to remove: " USERNAME
|
|
fi
|
|
|
|
# Remove Samba user
|
|
if pdbedit -L | grep -q "^$USERNAME:"; then
|
|
smbpasswd -x "$USERNAME"
|
|
echo "Samba user $USERNAME removed."
|
|
else
|
|
echo "Samba user $USERNAME does not exist."
|
|
fi
|
|
|
|
# Remove system user
|
|
if id "$USERNAME" &>/dev/null; then
|
|
userdel -r "$USERNAME"
|
|
echo "System user $USERNAME removed (including home directory)."
|
|
else
|
|
echo "System user $USERNAME does not exist."
|
|
fi
|