How to get Id of public key without importing private key

gnupgkeychainpgp

If I run the following on a private key to install it in my keyserver:

gpg --allow-secret-key-import --import my_private.key

It will import an associated public key presumably from a keyserver?

gpg: key xyz...: public key "example@example.com" imported

My question is: How can I find out the ID of this public key without having to install the private key to my keychain?

Best Answer

Just call the gpg command line tool and pass it the keyfile as an option

$ gpg my_private.key
sec  4096R/1234ABCD 2017-09-12 foo@bar.com

The long version (without warning "gpg: WARNING: no command supplied. ..." - since gnupg-version >= 2.1.23 - found this here):

gpg --import-options show-only --import my_private.key
Related Question