Created
February 4, 2019 15:56
-
-
Save silas/fd3d35f814adc54c97f381921b5056d5 to your computer and use it in GitHub Desktop.
Gitolite tool to sync SSH keys from Github
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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