Created
January 18, 2014 00:16
-
-
Save runbrun/8484147 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
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!" | |
chmod 755 /home/$username | |
fi | |
else | |
echo "Only root may add a user to the system" | |
exit 2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment