Skip to content

Commit 336a307

Browse files
authored
Create create_user3.sh
1 parent e2917ea commit 336a307

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

create_user3.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Purpose - Script to add a user to Linux system including passsword
3+
# Author - Vivek Gite <www.cyberciti.biz> under GPL v2.0+
4+
# ------------------------------------------------------------------
5+
# Am i Root user?
6+
if [ $(id -u) -eq 0 ]; then
7+
read -p "Enter username : " username
8+
read -s -p "Enter password : " password
9+
egrep "^$username" /etc/passwd >/dev/null
10+
if [ $? -eq 0 ]; then
11+
echo "$username exists!"
12+
exit 1
13+
else
14+
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
15+
useradd -m -p "$pass" "$username"
16+
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
17+
fi
18+
else
19+
echo "Only root may add a user to the system."
20+
exit 2
21+
fi

0 commit comments

Comments
 (0)