Propagating SSH Keys with GitHub and Fabric


- Jacob Haslehurst

New Server!

How does everyone log in?




Passwords?




They Suck




Sharing a SSH Key




That Sucks



Putting everyone's existing public keys on the server?




Tedious



Unless...

Solution


https://api.github.com/users/hzy/keys [ { "id": 3201249, "key": "ssh-rsa AAAAB3NzaC1yc2EAAA..." }, { "id": 5148152, "key": "ssh-rsa AAAAB3NzaC1yc2EAAA..." }, { "id": 5307737, "key": "ssh-rsa AAAAB3NzaC1yc2EAAA..." } ]
keys = []
base_url = 'https://api.github.com'
members = requests.get(base_url + '/orgs/gizmag/members').json()
for member in members:
    resp = requests.get(
        base_url + '/users/{login}/keys'.format(**member)
    ).json()
    for item in resp:
        keys.append(item['key']
@task
def populate_authorized_keys():
    keys_file = StringIO()
    get('~/.ssh/authorized_keys', keys_file)
    keys_file.seek(0)
    keys = [x.strip('\n') for x in keys_file.readlines() if x != '\n']

    # get the GitHub keys

    # write it out to the server
    out_file = StringIO()
    for key in keys:
        out_file.write(key + '\n')

    out_file.seek(0)
    put(out_file, '~/.ssh/authorized_keys')




$ fab populate_authorized_keys




Thanks

Copy of ssh-github-fabric

By Justin Arulnathan

Copy of ssh-github-fabric

  • 544