Created
December 5, 2017 18:25
-
-
Save codersofthedark/88b48597cd0ee807cb06d761a12042af to your computer and use it in GitHub Desktop.
Creates a key based passwordless SSH User and gives it sudo rights
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 | |
NEWUSER=$1 | |
USERPUBKEY=$2 | |
if [ -z "$NEWUSER" ]; then | |
echo "Username required" | |
exit 1; | |
fi | |
if [ -z "$USERPUBKEY" ]; then | |
echo "Public key required - Enclose argument in quotes!" | |
exit 1; | |
fi | |
useradd -d /home/$NEWUSER -s /bin/bash -m $NEWUSER && echo "User Created" | |
cd /home/$NEWUSER && echo "Changed Diretory" | |
mkdir .ssh && echo "Create .ssh directory" | |
chmod 700 .ssh && echo "Made .ssh executable" | |
touch .ssh/authorized_keys && echo "Created Authorised Keys Folder" | |
chmod 600 .ssh/authorized_keys && echo "Changed authorized keys permission" | |
echo $USERPUBKEY > .ssh/authorized_keys && echo "Added Pub Key" | |
usermod -a -G sudo $NEWUSER && echo "Added to user to SUDO" | |
chown -R $NEWUSER:$NEWUSER .ssh && echo "Made user ownder of .ssh dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment