Skip to content

Instantly share code, notes, and snippets.

@ss-o
Forked from angela-d/gpg-key-migration.md
Last active September 4, 2022 20:50
Show Gist options
  • Save ss-o/88093ae3b20e2c5fb71d55a6aa160a8e to your computer and use it in GitHub Desktop.
Save ss-o/88093ae3b20e2c5fb71d55a6aa160a8e to your computer and use it in GitHub Desktop.
Move GPG Keys from One Machine to Another

Migrate GPG Keys from One Workstation to Another

Replace [your key] with your key ID

To obtain your key ID

gpg --list-secret-keys --keyid-format LONG

Which returns something like

/home/angela/.gnupg/pubring.kbx
-------------------------------
sec   rsa4096/[your key] 2018-03-30 [SC]
      ABCDEFGHIJKLMNOPQRSTUVWXYZ
uid                 [ unknown] angela (KEY NAME) <user@domain>
ssb   rsa4096/ABCDEFGHIJKL 2018-03-30 [E]

After the key size rsa4096/ is your key ID.


Export the key in preparation to move it

gpg --export -a [your key] > gpg-pub.asc

Prepare the secret key for migration (if password protected, you'll be prompted to enter it)

gpg --export-secret-keys -a [your key] > gpg-sc.asc

Find them

ls -l gpg*.asc

Drag the key pair from the current directory to your USB stick or however else you move them.

Once on the new machine, import them

gpg --import gpg-pub.asc

If password protected, you'll be prompted to enter it

gpg --import gpg-sc.asc

If you need to adjust the trust level

gpg --edit-key [your key]

KeyBase

Import Keybase PGP to GPG

After installing the keybase command-line tool onto a new / fresh computer, you may want to import your PGP key to the local keyring so that you may use the keys with GPG.

Import your PUBLIC PGP key:

keybase pgp export|gpg --import -

For your SECRET PGP key, you have to be more assertive:

keybase pgp export -s|gpg --allow-secret-key-import --import -

You will then want to trust the keys as your own, so that GPG can be "sure" they're safe to use

gpg --edit-key [email protected]
trust
5
y
save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment