Last active
June 28, 2022 08:22
-
-
Save awkward-ninja/ef73bc224ee596ecbd96934a34f3199c to your computer and use it in GitHub Desktop.
GPG Import / Export / Clone
This file contains 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
# Based on the following articles | |
# https://blog.programster.org/generating-gpg-master-and-subkeys | |
# https://risanb.com/code/backup-restore-gpg-key/ | |
# https://gist.github.com/oseme-techguy/bae2e309c084d93b75a9b25f49718f85 | |
gpg_keyid() { | |
gpg2 --list-secret-keys \ | |
| sed -n 's/^ \(\w*\)/\1/p' | |
} | |
gpg_keygrip() { | |
gpg2 --with-keygrip --list-key $(gpg_keyid) \ | |
| sed -n 's/^ Keygrip = \(\w*\)/\1/p' \ | |
| head -n 1 | |
} | |
gpg_export() { | |
gpg2 --export-secret-keys --armor $(gpg_keyid) > gpg-keys.txt | |
gpg2 --export-ownertrust > gpg-trust.txt | |
} | |
gpg_import() { | |
gpg2 --import gpg-keys.txt | |
gpg2 --import-ownertrust < gpg-trust.txt | |
} | |
gpg_clone() { | |
gpg_export | |
mkdir gpg-home | |
chmod 700 gpg-home | |
GNUPGHOME=gpg-home gpg_import | |
rm gpg-home/private-keys-v1.d/$(gpg_keygrip).key | |
} | |
command=$1 | |
shift | |
gpg_$command $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment