Created
September 13, 2019 16:57
-
-
Save eguyd/50ef2923852f49e7c23599a15ac909ed to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# SECTION 1 | Set Host IPv4 | |
# localhost: '127.0.0.1' # ADD USER TO LOCAL HOST | |
# remotehost <reopteIPv4> # ADD USER TO REMOTE HOST | |
# SECTION 2 | Generate Login Details | |
set -e # STOP IF ANY ERROR | |
if [ $(id -u) -eq 0 ]; then # VERIFY ROOT THEN IF ROOT | |
read -p "Enter username : " username # ENTER USER NAME | |
read -s -p "Enter password : " password # ENTER PASSWORD | |
# shellcheck disable=SC2196 | |
grep -E "^$username" /etc/passwd >/dev/null # VERIFY USERNAME NOT IN etc/passw? | |
if [ $? -eq 0 ]; then # IF NO | |
echo "$username USER NAME UNAVAILABLE!" # OUTPUT USERNAME UNAVAILABLE | |
exit 1 # BREAK | |
else | |
# sudo adduser --disabled-password --gecos "" ' "$username" ' ; # ADD USER DISABLED PASSWORD | |
# sudo touch /home/'"$username"'/.ssh/authorized_keys ; # CREATE SSH DIRECTORY | |
# ' "echo $pubkey | sudo tee /home/$username/.ssh/authorized_keys; # APPEND PUBLIC KEY TO AUTHORIZED KEY FILE | |
# sudo chown -R $username:$username /home/$username/.ssh | |
# sudo chmod 700 /home/$username/.ssh ; # SET SSH FOLDER OWNERSHIP + PERMISSIONS | |
# sudo chmod 600 /home/$username/.ssh/authorized_keys" ; # SET AUTHORIZED KEY FOLDER OWNERSHIP + PERMISSIONS | |
useradd -m -p "$username" "$password" | |
usermod -a -G sudo "$username" | |
[ $? -eq 0 ] && echo "$username"succesly added! || echo "FAILED TO ADD $username" | |
fi | |
echo "PERMISSIONS DENIED" | |
exit 2 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment