Linux Quick Tip: Adding GitHub Keys as Authorized Keys
As a software developer, I constantly work with a bunch of virtual environments used for testing.
The first step I do —Switch from password ssh authorization to authorization by public key. Let me share with you a handy batch that will add all of your GitHub keys as authorized keys.
USERNAME=yourgithubusername mkdir -p ~/.ssh if ! [[ -f ~/.ssh/authorized_keys ]]; then echo "Creating new ~/.ssh/authorized_keys" touch ~/.ssh/authorized_keys fi keys=`curl https://api.github.com/users/$USERNAME/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
Usually I run it as
curl -L http://bit.ly/easytoremembershortcut | bash -s
This approach has already saved me a lot of time!