Ubuntu – How to match exported OpenPGP public and private key pairs

gnupgopenpgp

I have a few backed up public and private key files. How can I check which public key file corresponds to which private key file?

I had generated 2048 byte public and private GnuPG key pairs using

gpg --gen-key

To backup the public key(s), I exported them using

gpg --armor --output ~/gpg_keys_backup/<Public Key Id>-public.key --export <Public Key Id>

To backup the private key(s), I exported them using

gpg --armor --output ~/gpg_keys_backup/<Private Key ID>-private.key --export-secret-keys <Private Key ID>

How do I determine which backed up keys belong to a pair?

Best Answer

By listing the secret key file's contents, you can query which public key a secret key belongs to.

gpg --list-packets [secret-key-file] | head
:secret key packet:
        version 4, algo 1, created 1356475387, expires 0
        pkey[0]: [8192 bits]
        pkey[1]: [17 bits]
        gnu-dummy S2K, algo: 0, simple checksum, hash: 0
        protect IV: 
        keyid: 4E1F799AA4FF2279

The last line quoted keyid contains the public key's long key ID.

Related Question