Skip to content

Instantly share code, notes, and snippets.

@nmattia
Last active June 26, 2016 13:33
Show Gist options
  • Save nmattia/1c017c65172c3ec6e57881860cedbf16 to your computer and use it in GitHub Desktop.
Save nmattia/1c017c65172c3ec6e57881860cedbf16 to your computer and use it in GitHub Desktop.
Use github to get ssh authorized keys
#!/bin/sh
#
# Fetches SSH keys from a github user
# Big kudos to @zimbatm for inspiration: https://gist.github.com/zimbatm/3166cc0bbb46551fe67e
#
# Usage:
# curl -L https://goo.gl/Jj330b | user=<github username> sh
#
if [ -z "$user" ]; then
user=nmattia
fi
mkdir -m 0700 -p "$HOME/.ssh"
curl "https://api.github.com/users/$user/keys" | grep 'key":'| sed -e 's/.*"\(ssh-.*\)".*/\1/' > "$HOME/.ssh/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment