Let assume that I have a list of three key pair on my bash screen when I run the following commands:
gpg2 --list-keys
and
gpg2 --list-secret-keys
My question is, when I run the following command to verify a signed file, which key pair is used by this tool?
gpg2 --verify test.sig
Does it check all the signing keys one by one to find a matched one or finish all the keys?
An OpenPGP signature includes a reference to the key used for signing. GnuPG will use this exact key to verify the signature.
An example for some document signed by my own key, analyzed using
gpg --list-packets
:8E78E44DFB1B55E9
is a signing subkey used for the signature (I enabled long key IDs, in case you wonder about the 16 character hex IDs).For encryption, it is possible to hide the recipient key. In this case, GnuPG has to try all available encryption keys to decrypt the message.
Further keys might be involved for validating the signature, which means finding trust paths in the web of trust: but this is another, large topic.