Export and Import GPG private key

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

Example output:

pub   4096R/ABC12345 2020-01-01 [expires: 2025-12-31]
uid                  Your Name <[email protected]>
sub   4096R/DEF67890 2020-01-01 [expires: 2025-12-31]

Remember the ID of your key (second column, after the slash, e.g. “ABC12345”). If you have a “sub” entry, you can ignore it.

Run this command to export your key:

gpg --export-secret-keys YOUR_ID_HERE > private.key

Run this command to import your key:

gpg --import private.key