How to recover keys

I recently did a fresh installation of Ubuntu 20.04 on my workstation. I made a complete backup of my home directory, and have been pulling out the bits that I need. I had set up a signing key for my git commits, and failed to export it before the reinstallation. Of course, the file are still in ~/.gnupg. I'm not exactly sure of the structure in this directory, such as where the public and private keys are, and if just moving them over is sufficient. I'm worried about doing something stupid and messing up my existing installation.


Solution 1:

First of all copying over ~/.gnupg to a new machine should be fine and working. See Moving/Copying your PGP Keys as reference.

Accordingly to the git documentation Git - Signing Your Work you should be able to see your existing key via:

gpg --list-keys

Your existing key should be listed there.

If it is check git repo or global configuration if and what key is currently set:

  • for "repo only" configuration (you have to be within your repo directory):

    git config user.signingkey
    
  • global:

    git config --global user.signingkey
    

If key from gpg --list-keys command and git config match you should be fine.

If git user.signingkey config is empty set it with

git config --global user.signingkey 0A46826A

where "0A46826A" should be your existing key hash.