Creating new user
This commit is contained in:
parent
53e99dd148
commit
b52cf56f46
1 changed files with 30 additions and 1 deletions
31
script.sh
31
script.sh
|
|
@ -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
|
||||||
Loading…
Reference in a new issue