-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ed195
commit 1d35856
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
# Purpose - Script to add a user to Linux system including passsword | ||
|
||
if [ $(id -u) -eq 0 ]; then | ||
read -p "Enter username : " username | ||
read -s -p "Enter password : " password | ||
egrep "^$username" /etc/passwd >/dev/null | ||
if [ $? -eq 0 ]; then | ||
echo "$username exists!" | ||
exit 1 | ||
else | ||
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) | ||
useradd -m -p "$pass" "$username" | ||
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!" | ||
fi | ||
else | ||
echo "Only root may add a user to the system." | ||
exit 2 | ||
fi |