Skip to content

Instantly share code, notes, and snippets.

@nlopez
Last active September 22, 2017 18:27
Show Gist options
  • Save nlopez/d714499bec4430086d4db256746e5a53 to your computer and use it in GitHub Desktop.
Save nlopez/d714499bec4430086d4db256746e5a53 to your computer and use it in GitHub Desktop.
Get your authorized keys from GitHub - don't try this at home^Wwork!
# Requires OpenSSH 6.9/6.9p1 (2015-07-01)
# These steps will use the https://github.com/$USER.keys keys as SSH authorized keys
# Your SSH username and GitHub username must match
# If they don't, you can add some translation to the github_authorized_keys script
#
# By default, if no match is found from this command, auth will fall back to
# AuthorizedKeysFile. If you don't want this behavior you can set AuthorizedKeysFile /dev/null
# But for reliability reasons, I don't encourage this
# Create GitHub authorized keys script
cat <<'EOF' | sudo tee /usr/local/sbin/github_authorized_keys
#!/bin/sh
/usr/bin/curl -sS -m 10 https://github.com/$1.keys
EOF
# Set appropriate permissions
sudo chmod 0755 /usr/local/sbin/github_authorized_keys
sudo chown root:root /usr/local/sbin/github_authorized_keys
# In sshd_config:
AuthorizedKeysCommand /usr/local/sbin/github_authorized_keys %u
AuthorizedKeysCommandUser nobody
# Restart sshd and go!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment