From dd55f98281c1c0c28a5f8df3c87031bc84dd450d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 26 Jun 2025 00:23:53 +0000 Subject: custom scripts used to manage the public access system --- deleteuser.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 deleteuser.sh (limited to 'deleteuser.sh') diff --git a/deleteuser.sh b/deleteuser.sh new file mode 100755 index 0000000..d4a3841 --- /dev/null +++ b/deleteuser.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Check if username is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +USERNAME="$1" +JAIL_DIR="/home/publicaccess" +USER_HOME="$JAIL_DIR/home/$USERNAME" +PASSWD_FILE="$JAIL_DIR/etc/passwd" + +# Check if the user exists on the system +if ! id "$USERNAME" >/dev/null 2>&1; then + echo "User '$USERNAME' does not exist on the host system." +else + echo "Removing user '$USERNAME' from the system..." + sudo userdel -r "$USERNAME" +fi + +# Remove user from jail passwd file if present +if [ -f "$PASSWD_FILE" ]; then + sudo sed -i "/^$USERNAME:/d" "$PASSWD_FILE" +fi + +# Delete the user's jailed home directory +if [ -d "$USER_HOME" ]; then + echo "Deleting jailed home directory: $USER_HOME" + sudo rm -rf "$USER_HOME" +fi + +# Remove from group file if applicable +GROUP_FILE="$JAIL_DIR/etc/group" +if [ -f "$GROUP_FILE" ]; then + sudo sed -i "/^$USERNAME:/d" "$GROUP_FILE" +fi + +echo "User '$USERNAME' deleted from system and jail (if present)." +exit 0 -- cgit v1.2.3