Skip to content

Instantly share code, notes, and snippets.

@kaji-bikash
Last active January 17, 2018 23:42
Show Gist options
  • Save kaji-bikash/168422c32e95fde3f78ac022e7235b9f to your computer and use it in GitHub Desktop.
Save kaji-bikash/168422c32e95fde3f78ac022e7235b9f to your computer and use it in GitHub Desktop.
#! /bin/bash
#Assumptions
#Default user deploy whose SSH authorized_keys is to modify
#SSH authorized_keys is in the format ssh-rsa key
home=${home:-deploy}
username=$1
#get public key from a github
KEY="https://github.com/$username.keys"
curl --silent $KEY -o /tmp/$username.pub
ssh_auth_file=`eval echo ~${home}/.ssh/authorized_keys`
##Append found keys to authorized_keys file
while read line
do
echo $line >> ${ssh_auth_file}
done <"/tmp/${username}.pub"
#Simulate idempotence/de-duplication
cat $ssh_auth_file | sort -u -k1,2 > ${ssh_auth_file}.uniq
mv ${ssh_auth_file}.uniq ${ssh_auth_file}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment