Skip to content

Instantly share code, notes, and snippets.

@lmacken
Created June 5, 2016 06:00
Show Gist options
  • Save lmacken/dc9d7752def86526dd198abb71e191a5 to your computer and use it in GitHub Desktop.
Save lmacken/dc9d7752def86526dd198abb71e191a5 to your computer and use it in GitHub Desktop.
Migrates a 'pass' setup to a different GPG key
#!/usr/bin/env python3
# Re-encrypt all pass files with a different GPG key
# 1) First, add your new key to ~/.password-store/.gpg-id
# 2) Run this script.
# 3) Confirm that things work
# 4) Remove the old backup keys with `find ~/.password-store -name '*.old' | xargs rm`
import os
import shutil
import subprocess
KEY = 'ADCE8DEB'
for root, dirs, files in os.walk(os.path.expanduser('~/.password-store')):
for file in files:
filename = os.path.join(root, file)
if filename.endswith('.gpg'):
assert os.path.exists(filename)
print(filename)
old = filename + '.old'
shutil.move(filename, old)
p = subprocess.Popen('gpg2 -d {} | gpg2 -r {} -u {} -e -o {}'.format(old, KEY, KEY, filename), shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment