Skip to content

Instantly share code, notes, and snippets.

@TheNicholasNick
Last active November 3, 2018 08:12
Show Gist options
  • Save TheNicholasNick/c6dd3c7b3bfb6f66fa77e354368d0439 to your computer and use it in GitHub Desktop.
Save TheNicholasNick/c6dd3c7b3bfb6f66fa77e354368d0439 to your computer and use it in GitHub Desktop.
Script to add SSH keys to authorized_keys file
# 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 ""
@TheNicholasNick
Copy link
Author

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 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment