Skip to content

Instantly share code, notes, and snippets.

@silas
Created February 4, 2019 15:56
Show Gist options
  • Save silas/fd3d35f814adc54c97f381921b5056d5 to your computer and use it in GitHub Desktop.
Save silas/fd3d35f814adc54c97f381921b5056d5 to your computer and use it in GitHub Desktop.
Gitolite tool to sync SSH keys from Github
#!/usr/bin/env python3
import glob
import hashlib
import os
import urllib.request
def update_keys(local_user, github_user):
with urllib.request.urlopen('https://github.com/%s.keys' % github_user) as f:
keys = f.read().decode('utf-8').strip().splitlines()
current_keys = glob.glob('keydir/%s@github-*.pub' % local_user)
for path in current_keys:
os.remove(path)
for key in keys:
m = hashlib.md5()
m.update(key.encode('utf-8'))
path = 'keydir/%s@github-%s.pub' % (local_user, m.hexdigest())
with open(path, 'w+') as f:
f.write(key)
update_keys('admin', 'GITHUB_USER')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment