From b52cf56f4689e4c7b8e8c3a9d229fd829d9976f2 Mon Sep 17 00:00:00 2001 From: joeri Date: Sat, 3 Aug 2024 13:13:20 +0200 Subject: [PATCH] Creating new user --- script.sh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 35613ad..6490007 100644 --- a/script.sh +++ b/script.sh @@ -47,4 +47,33 @@ case "$DISTRO" in *) echo "Unsupported distribution: $DISTRO" exit 1 -esac \ No newline at end of file +esac + +# Function to create a new user +create_new_user() { + echo "Enter the username for the new user: " + read USERNAME + + # Check if the username already exists + if id "$USERNAME" &>/dev/null; then + echo "User $USERNAME already exists!" + else + echo "Enter the password for the new user: " + read -s PASSWORD + + # Create the user and set the password + sudo useradd -m "$USERNAME" + echo "$USERNAME:$PASSWORD" | sudo chpasswd + echo "User $USERNAME created successfully!" + fi +} + +# Asking if the user wants to create a new user +echo "Do you want to create a new user? (y/n): " +read CREATE_USER + +if [ "$CREATE_USER" = "y" ]; then + create_new_user +else + echo "No new user will be created." +fi \ No newline at end of file