Skip to content

Instantly share code, notes, and snippets.

@geekdada
Forked from rtlong/get-keys-for-github-user.sh
Created February 13, 2017 15:50
Show Gist options
  • Save geekdada/9c1df4d721174b27d7b72904ef86b0a9 to your computer and use it in GitHub Desktop.
Save geekdada/9c1df4d721174b27d7b72904ef86b0a9 to your computer and use it in GitHub Desktop.
Put public keys for a github user in ~/.ssh/authorized keys with mucho ease
IFS="$(printf '\n\t')"
mkdir -p ~/.ssh
if ! [[ -f ~/.ssh/authorized_keys ]]; then
echo "Creating new ~/.ssh/authorized_keys"
touch ~/.ssh/authorized_keys
fi
user=$1
keys=`curl https://api.github.com/users/$user/keys | grep -o -E "ssh-\w+\s+[^\"]+"`
for key in $keys; do
echo $key
grep -q "$key" ~/.ssh/authorized_keys || echo "$key" >> ~/.ssh/authorized_keys
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment