Created
August 24, 2018 11:32
-
-
Save lyashevska/bd9c5b084e8833b50aaac93cf678778b to your computer and use it in GitHub Desktop.
add local user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# this script will create new user accounts | |
# enforce execution with a root priviledges, | |
# return status 1 if not root | |
if [[ "${UID}" -eq 0 ]] | |
then | |
# enter the username (login), | |
read -p 'Enter the username to create: ' USER_NAME | |
# the name for the person who will be using account | |
read -p 'Enter the real name: ' COMMENT | |
# get initial password | |
read -p 'Enter the password to use for the account: ' PASSWORD | |
# create a new user with a input provided by the user | |
useradd -c "${COMMENT}" -m ${USER_NAME} | |
# Check to see if the useradd command succeeded | |
if [[ "${?}" -ne 0 ]] | |
then | |
echo 'The account was not created' | |
exit 1 | |
fi | |
# Set the password for the user | |
echo ${PASSWORD} | passwd --stdin ${USER_NAME} | |
# Check to see if the passwd command succeeded | |
if [[ "${?}" -ne 0 ]] | |
then | |
echo 'The account was not created' | |
exit 1 | |
fi | |
# Force password change on first login | |
passwd -e ${USER_NAME} | |
# display the user name, password, the host where the account was created | |
echo "User name: $USER_NAME" | |
echo "Password: $PASSWORD" | |
HOSTNAME=$(uname -n) | |
echo "Host: $HOSTNAME" | |
else | |
echo "The sript requires root priviledges" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great!
would be better however to do like