26

When given a file with an armored public GnuPG key, i.e. a file (pubkey.gpg) that was created with:

gpg -r 0xDEADBEEF --export --armored > pubkey.gpg

What is the best way to get information such as the finger print in that file, without importing it into my keyring?

The best way I found so far (and I am not happy with) is:

gpg --dry-run --import pubkey.gpg

Naturally, I grepped the gpg man page, but didn't find an obvious solution.

4 Answers 4

8

I don't know that gpg has an option for this, but here's a more flexible workaround for extracting information from the key file:

mkdir temp-gnupg-dir
export GNUPGHOME=temp-gnupg-dir
gpg --import pubkey.gpg
gpg --list-keys
rm -r temp-gnupg-dir

Instead of the GNUPGHOME environment variable, you can pass --homedir=temp-gnupg-dir to every gpg invocation.

2
  • This is not pretty, but it is useful to know what options are not available, and this is a solution. So I thank you for that.
    – Chen Levy
    Commented Aug 8, 2010 at 13:27
  • 1
    While this will work, it's way more complicated than necessary. Below I posted how to do it without any of the importing or keychain switching.
    – jm3
    Commented Nov 17, 2013 at 3:17
18

To print the fingerprint of an on-disk armored key without importing it, just use --with-fingerprint:

> gpg --with-fingerprint jm3.asc

pub  1024R/9112BC51 1996-02-05 john manoogian <jm3@*>
Key fingerprint = C9 DC 27 29 0E 1A DB 50  21 C8 64 08 15 29 41 86

uid                            john manoogian <jm3@foo...
uid                            john manoogian <jm3@bar...
uid                            john manoogian <jm3@baz...
uid                            john manoogian <jm3@qux...

Voilà!

3
  • This will create a gnupg directory and a default keyring if one does not exist. The accepted answer does not have that side-effect. Commented Aug 11, 2014 at 3:30
  • --with-fingerprint is optional.
    – x-yuri
    Commented May 20, 2015 at 13:21
  • 1
    This no longer works. My gpg version is 2.2.5.
    – Dan Milon
    Commented May 8, 2018 at 12:15
6

You can checkout Kazu Yamamoto's PGP packet visualizer which displays the packet format of OpenPGP (RFC 4880) and PGP version 2 (RFC 1991).

To fetch and compile:

git clone http://github.com/kazu-yamamoto/pgpdump
cd pgpdump
./configure --prefix=/usr/local/ && make && sudo make install

Using it is even simpler:

pgpdump pubkey.gpg

There is also a cgi-bin interface available on this site: http://www.pgpdump.net/cgi-bin/pgpdump

2
  • 1
    This is awesome! And kudos to a fellow Haskeller Kazu :) BTW, pgpdump is packaged by Debian (and possibly other distros, too), so check it in the repositories before compiling it yourself. Commented Mar 1, 2014 at 7:33
  • 4
    There's a similar to pgpdump but not that verbose output from gpg --list-packets
    – JSmith
    Commented May 21, 2014 at 7:24
0

There is more simple solution (tested for GnuPG 2.2.27):

gpg pubkey.gpg

Or, machine-readable result (some upgrades for @jm3 answer):

gpg --with-fingerprint --with-colons pubkey.gpg
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 8, 2023 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .