How do I make GnuPG (specifically version 1.4.12) display the full, 64-bit (8-byte) key ID for a key on a keyring on my system?

Doing gpg --list-keys --fingerprint XXXXXXXX only displays the 32-bit portion of the key ID, which I already know, and the fingerprint (which at least in the past has not necessarily been the same as the key ID, although the rightmost 32 bits do match in this particular case).

Googling turned up some pages about the importance of specifying the 64-bit key ID to minimize the risk of collisions, and some GnuPG options which want or accept a long key ID, but I couldn't find anything about how to actually display the long key ID.


Alternatively you can use:

gpg --keyid-format LONG -k 0xDEADBEEF


gpg --keyid-format 0xLONG -k 0xDEADBEEF
| improve this answer | |
  • This is actually even better IMO, as the output is much more readable than in Paulo's suggestion (which is still valid). – a CVn Sep 30 '13 at 7:21
  • 5
    Yeah, I prefer the longer format so much that I have "keyid-format 0xLONG" in my gpg.conf so I don't have to specify it each time. Using --keyid-format 0xSHORT will display keys the default way. – Ben Sep 30 '13 at 8:56
  • 1
    The reason why Paulo's suggestion is better is that the --with-colons format is guaranteed to work, because the --with-colons option is guaranteed to be backwards-compatible, for programmatic access. Other options do not necessarily have that output format guarantee. – Christopher Jun 10 '15 at 23:58
  • 1
    Except the positioning of some values on some platforms isn't always identical. It usually is, but not quite consistently enough for true, programmatic platform independence. Unfortunately I can't recall which variation broke the pattern, but I do recall it being discussed on gnupg-users; I believe in relation to a discussion about counting the number of keys in a keyring. – Ben Jun 14 '15 at 9:01
  • @Christopher That is certainly a consideration when you're scripting something, or trying to parse the output. For human consumption, however, it certainly is not a major consideration, as when properly calibrated, the human brain is a highly adaptive fuzzy logic matcher. – a CVn Jul 23 '15 at 18:06

You can see the long key ID using the option --with-colons (yes, very intuitive).

To print only the long key ID, use something like:

$ gpg --list-keys --with-colons XXXXXXXX | awk -F: '/^pub:/ { print $5 }'
| improve this answer | |

Just to point out a sanely named option to remember,

GnuPG 2.2.13 on macOS Catalina 10.15.4, --list-signatures option displays the key ID as well:

$ gpg --list-signatures
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.