Skip to content

Instantly share code, notes, and snippets.

@Gowee
Last active July 7, 2026 13:48
Show Gist options
  • Select an option

  • Save Gowee/396128e4d926d93381079d92e902fa3a to your computer and use it in GitHub Desktop.

Select an option

Save Gowee/396128e4d926d93381079d92e902fa3a to your computer and use it in GitHub Desktop.
Turn private keys in Gravity registry into .ssh/authorized_keys
#!/bin/sh
# ./extract-gravity-keys.sh PATH_TO_PARENT_FOLDER_OF_GRAVITY >> ~/.ssh/authorized_keys
BASE="${1:-.}"
python3 -c "
import base64, struct, json, glob, os, sys
def pem_to_ssh_ed25519(pem):
b64 = ''.join(l for l in pem.split('\n') if not l.startswith('-----'))
der = base64.b64decode(b64)
raw = der[-32:]
algo = b'ssh-ed25519'
parts = [
struct.pack('>I', len(algo)) + algo,
struct.pack('>I', len(raw)) + raw,
]
return base64.b64encode(b''.join(parts)).decode()
base = sys.argv[1]
for f in sorted(glob.glob(os.path.join(base, 'gravity/registry/*.json'))):
with open(f) as fh:
d = json.load(fh)
pub = pem_to_ssh_ed25519(d['public_key'])
print(f'command=\"cat /var/lib/gravity/registry.json\" ssh-ed25519 {pub} {d[\"organization\"]}')
" "$BASE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment