Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script creates an account on the local system.
- # You will be prompted for the account name and password.
- # 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
- # Ask for the users name.
- read -p 'Enter the username to create: ' USER_NAME
- # Ask for the real name.
- read -p 'Enter the full name of the person who this account is for: ' COMMENT
- # Ask for the password.
- read -p 'Enter the password to use for the account: ' PASSWORD
- # Create user
- useradd -c "${COMMENT}" -m ${USER_NAME}
- # Check to see if the useradd command succeeded
- # We dont want to the tell the user that an account was created when it hasnt been
- if [[ "${?}" -ne 0 ]]
- then
- echo 'The account could not be created.'
- exit 1
- fi
- # Set the password for the user.
- echo ${PASSWORD} | passwd --stdin ${USER_NAME}
- if [[ "${?}" -ne 0 ]]
- then
- echo 'The password for the account could not be set.'
- exit 1
- fi
- # Force user to change password on first login.
- passwd -e ${USER_NAME}
- # Diplay the username, password and the host where the user was created.
- echo
- echo 'username:'
- echo "${USER_NAME}"
- echo
- echo 'password:'
- echo "${PASSWORD}"
- echo
- echo 'host:'
- echo "${HOSTNAME}"
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement