Export and import private GPG key

tags: linux, freebsd, openbsd, pgp, gpg

This is another note added while switching from Linux to FreeBSD on my laptop.

Obtain your private key ID by running command:

gpg --list-secret-keys

or shorter one:

gpg -K

You will something like this:

/home/sv/.gnupg/pubring.kbx
---------------------------
sec   rsa3072 2018-10-27 [SC] [expires: 2020-10-26]
      2907C3B6E0BAD508657B06FAE9BD8C827FB23D9E
uid           [ultimate] Slavik Svyrydiuk <svyrydiuk@gmail.com>
uid           [ultimate] Slavik Svyrydiuk <slavik@svyrydiuk.eu>
ssb   rsa3072 2018-10-27 [E] [expires: 2020-10-26]

You need the ID of your private key. In my case it is 2907C3B6E0BAD508657B06FAE9BD8C827FB23D9E

Run this command to export private key:

gpg --export-secret-keys 2907C3B6E0BAD508657B06FAE9BD8C827FB23D9E > privatekey.asc

If you have a few secret keys list them all after --export-secret-keys option.

Copy the key saved in file privatekey.asc to the machine you want to import it on.

To import the key on OpenBSD, run:

pgpk -a privatekey.asc

On Linux or FreeBSD:

gpg --import privatekey.asc

Thunderbird

To install Enigmail:

In Thunderbird, select Tools > Add-ons.
Use the search bar in the top right corner to search for Enigmail.
Select Enigmail from the search results and follow the instructions to install the add-on.