File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments