Skip to content

Instantly share code, notes, and snippets.

@norcalli
Created August 1, 2023 23:16
Show Gist options
  • Save norcalli/0df794eb05e2f615019fc0daf5e88887 to your computer and use it in GitHub Desktop.
Save norcalli/0df794eb05e2f615019fc0daf5e88887 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
p() {
echo "$@" >&2
}
test -z "$USERNAME" && USERNAME=$1
test -z "$USERNAME" && {
p "Usage: $0 <github_username>"
p "Alternatively, pass USERNAME (github username) in as an environment variable"
p "e.g. curl script.sh | env USERNAME=bigboi69 bash"
exit 1
}
GITHUB_KEYS="$(curl https://github.com/$USERNAME.keys | cut -d' ' -f1,2)"
if test -e ~/.ssh/authorized_keys; then
EXISTING_KEYS="$(cat ~/.ssh/authorized_keys | cut -d' ' -f1,2)"
else
EXISTING_KEYS=""
fi
p "Adding github keys to authorized keys."
printf "%s\n" "$EXISTING_KEYS" "$GITHUB_KEYS" | sort -u > ~/.ssh/authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment