Last active
February 13, 2017 15:50
-
-
Save rtlong/6790049 to your computer and use it in GitHub Desktop.
Put public keys for a github user in ~/.ssh/authorized keys with mucho ease
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
At the time of writing, https://github.com/musically-ut.keys will output the keys in
authorized_keys
friendly format and in plain text. That will avoid having to grep through the JSON looking for the keys.