GnuPG command to show key info from file

The good folks at the [email protected] mailing list had the answer:

For versions >= 2.1.23:

cat keyfile.key | gpg --with-colons --import-options show-only --import

For versions >= 2.1.13 but < 2.1.23:

cat keyfile.key | gpg --with-colons --import-options import-show --dry-run --import

GnuPG does not know a dedicated command for listing contents of a key file. Either use gpg --list-packets <keyfile> (but this is not a stable, machine-readable output) or define the keyfile as keyring and list keys instead. The old keyring format up to GnuPG 2.0 stored keys as a concatenation of the key's packets; so you can also use a key file as a keyring. At least GnuPG 2.1 and 2.2 still support the old keyring format, and I wouldn't expect this to change in near future.

gpg --with-fingerprint --with-colons --no-default-keyring --keyring <keyfile> --list-keys

Be sure to include --no-default-keyring, otherwise GnuPG will also print all keys in your user's keyring!

Tags:

Gpg