Click here to Skip to main content
15,881,424 members
Articles / Security
Tip/Trick

Add All Of Your github Keys As Authorized

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
26 Oct 2015MIT 4K   2  
One-liner to add all of the github keys as authorized to some test unix server

Introduction

As a software developer, I constantly work with a bunch of virtual environments used for test. The first step I do - is switch from password ssh authorization to authorization by public key. Let me share with you handy batch, that will add all of your github keys as authorized.

Batch

PowerShell
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

Usage

Usually I run it as:

PowerShell
curl -L http://bit.ly/easytoremembershortcut | bash -s

This approach has already saved me a lot of time.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Web Developer
Ukraine Ukraine
Web Developer, interested in bleeding age web technologies and projects.

Experienced and interested in:
- High load web projects, bespoke software development
- DevOps: Chef, Ansible, Vagrant
- NoSQL (mongodb)
- Client stack (javascript core, jquery, AngularJS, HTML5 apis)
- *AAS (Amazon beanstalk, Redhat openshift)
- MEAN & Pure JS stack (Javascript, AngularJS, Node.JS, MongoDB)


-> DevOps inquiries
-> Other inquiries
-> Follow me on Github

Comments and Discussions

 
-- There are no messages in this forum --