-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec3vid7project
executable file
·60 lines (44 loc) · 1.31 KB
/
lec3vid7project
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# The goal of this exercise is to create a shell script that adds users to the same Linux system as the script is executed on.
# Make sure the script is being executed with superuser privileges.
if [ "${UID}" -ne 0 ]
then
echo "RUN THE SCRIPT WITH ROOT PRIVILAGES"
exit 1
fi
# Get the username (login).
read -p 'Enter the username : ' USER_NAME
# Get the real name (contents for the description field).
read -p 'Enter actual name: ' COMMENT
# Get the password.
read -p 'enter the password to set: ' PASSWORD
# Create the user account with the password.
useradd -c "${COMMENT}" -m ${USER_NAME}
# Check to see if the useradd command succeeded.
# we don't want to tell the user that the account has been created when it has not been
if [ "${?}" -ne 0 ]
then
echo 'THe account could not be created'
exit 1
fi
# Set the password.
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
# Check to see if the passwd command succeeded.
if [ "${?}" -ne 0 ]
then
echo 'The password for the account could not be set'
exit 1
fi
# Force password change on first login.
passwd -e ${USER_NAME}
# Display the username, password, and the host where the user was created.
echo # leaves a blank space
echo 'username'
echo "${USER_NAME}"
echo
echo 'password'
echo "${PASSWORD}"
echo
echo 'Host'
echo "${HOSTNAME}"
exit 0