-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.sh
More file actions
executable file
·58 lines (50 loc) · 1.46 KB
/
user.sh
File metadata and controls
executable file
·58 lines (50 loc) · 1.46 KB
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
57
58
i
#!/bin/bash
#Purpose is to add user and password while setting parameter for them both .
clear
trap ""SIGHUP SIGINT
while true
do
echo -n "Create your username: "
read username
if [ ${#username} -gt 0 ]
then
if [ $(cat /etc/passwd | grep $username) ]
then
echo "Username is already in uses. Please choose another one."
elif [ ${#username} -gt 7 ] && [ ${#username} -lt 20 ]
then
break
else
echo "Username must be between 7 to 20 characters."
fi
else
echo "Username is invllid."
fi
done
# Get the password and check if they match.
while true
do
echo -n "Create a password no less than 6 characters"
echo -n "Password: "
read password
echo -n "Confirm password: "
read password_confirm
if [ ${#password} -gt 6 ] || [ ${#password_confirm} -gt 6 ]
then
if [ $password == $password_confirm ]
then
break
else
echo "Passwords do not match."
fi
else
echo "Password can not be less than 6 characters ."
fi
done
# Add user
useradd $username -m -s /bin/bash -G users
# Give user password
echo $username:$password | chpasswd
echo "Account created! Please login to your new account."
kill -HUP $PPID