Creating new user

This commit is contained in:
joeri 2024-08-03 13:13:20 +02:00
parent 53e99dd148
commit b52cf56f46

View file

@ -47,4 +47,33 @@ case "$DISTRO" in
*) *)
echo "Unsupported distribution: $DISTRO" echo "Unsupported distribution: $DISTRO"
exit 1 exit 1
esac 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