-
-
Save isopropylcyanide/1075a3ac21b9bd5649f516eb91fe5ae0 to your computer and use it in GitHub Desktop.
Shell script to create user accounts
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 | |
ROOT_UID=0 | |
SUCCESS=0 | |
E_USEREXISTS=70 | |
# Run as root, of course. (this might not be necessary, because we have to run the script somehow with root anyway) | |
if [ "$UID" -ne "$ROOT_UID" ] | |
then | |
echo "Must be root to run this script." | |
exit $E_NOTROOT | |
fi | |
#test, if both argument are there | |
if [ $# -eq 2 ]; then | |
username=$1 | |
pass=$2 | |
# Check if user already exists. | |
grep -q "$username" /etc/passwd | |
if [ $? -eq $SUCCESS ] | |
then | |
echo "User $username does already exist." | |
echo "please chose another username." | |
exit $E_USEREXISTS | |
fi | |
#Preerequisite for mkpasswd : whois | |
useradd -p `mkpasswd "$pass"` -d /home/"$username" -m -g users -s /bin/bash "$username" | |
#Allow no one else to access the home directory of the user | |
chmod 750 /home/"$username" | |
echo "the account is setup" | |
else | |
echo " Expected usage: ./autoadder username password" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment