Quickly add your github keys as authorized to your virtual server

As a software developer, I constantly work with a bunch of virtual environments used for testing. The first step I do — is switch from password ssh authorization to authorization by public key. AWS, for example, creates ec2 instances with unique preset access key. Let me share with you handy batch, that will add all of your github keys as authorized — it will allow you to simply login as `ssh user@yournewremoteserver` next session , rather than `ssh -i yourtemporaryaccesskeyforserver.pem user@yournewremoteserver`

Note: of course it is not suitable for production environments.


USERNAME=yourgithubusernamemkdir -p ~/.sshif ! [[ -f ~/.ssh/authorized_keys ]]; then
echo "Creating new ~/.ssh/authorized_keys"
touch ~/.ssh/authorized_keys
keys=`curl | grep -o -E "ssh-\w+\s+[^\"]+"`for key in $keys; do
echo $key
grep -q "$key" ~/.ssh/authorized_keys || echo "$key" >> ~/.ssh/authorized_keys


Usually I run it as:

curl -L  | bash -s

This approach has already saved me a lot of time.

Software engineer, with project management background. Founder @ — cool automation for the people :) — have a problem that needs to be solved?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store