Skip to content

Instantly share code, notes, and snippets.

@kulbshar
Created July 8, 2018 01:07
Show Gist options
  • Save kulbshar/9e042fd73f10612baa7ed1dc7680737a to your computer and use it in GitHub Desktop.
Save kulbshar/9e042fd73f10612baa7ed1dc7680737a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Make Sure the script is being executed with superuser privileges.
if [[ "${UID}" -ne 0 ]]
then
echo "Please run with sudo or as root."
exit 1
fi
# Get the username (Login)
read -p "Enter the username(Login): " USER_NAME
# Get the real Name (Content for the description field).
read -p "Enter the real name (Content for desc): " COMMENT
# Get the passowrd.
read -p "Enter the password: " PASSWORD
# Create the user with the password.
useradd -c "${COMMENT}" -m ${USER_NAME}
# Check to see if the useradd command succeeded.
if [[ "${?}" -eq 0 ]]
then
echo " User ${USER_NAME} successfully created"
fi
# Set the password.
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
# Force password change on the first Login.
passwd -e ${USER_NAME}
# Check to see if the password command succeeded.
if [[ "${?}" -eq 0 ]]
then
echo "Password Created successfully for user ${USER_NAME}"
fi
# Display the username, password, and the host where the user was created.
grep -i "${USER_NAME}" /etc/passwd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment