Last active
November 3, 2018 08:12
-
-
Save TheNicholasNick/c6dd3c7b3bfb6f66fa77e354368d0439 to your computer and use it in GitHub Desktop.
Script to add SSH keys to authorized_keys file
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
# curl -L https://domain/addkeys | bash -s | |
mkdir -p ~/.ssh | |
echo "" | |
if ! [[ -f ~/.ssh/authorized_keys ]]; then | |
echo "Creating new ~/.ssh/authorized_keys" | |
touch ~/.ssh/authorized_keys | |
fi | |
chmod 700 ~/.ssh | |
chmod 600 ~/.ssh/* | |
cat <<'EOT' >> ~/.ssh/authorized_keys | |
# one key per line | |
EOT | |
echo "Keys added." | |
echo "Current keys in authorized_keys file:" | |
cat ~/.ssh/authorized_keys | while read KEY; do | |
echo "$KEY" | cut -d ' ' -f3-; | |
done; | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
named the file here addkey.sh to get the code highlighting - don't need the extension on the actual file you put on the webserver ;)