Search code examples
gnupg

Can I effectively choose gnupg recipients by email address?


We have a perl program that generates gpg encrypted files for multiple folks.

Today, we added dan@example.com. When I run the encryption script, it happily encrypts the file for dan@example.com using jordan@example.com. This is presumably because jordan@example.com was in my keyring first.

I've tested from the command line, and if I use gpg -r dan@example.com --encrypt foo.txt, the friendly client chooses to use the public key for jordan@example.com, instead of the more explicit dan@example.com.

Of course, if I use key ids it works, but that's not really what we've got here. Is there a way to tell gnupg to use the more explicit email address without resorting to key ids?


Solution

  • This is documented in the manual page that comes with gpg. Section "HOW TO SPECIFY A USER ID" you find the option "By exact match on an email address.". So the answer to your question is to use angle braces such as <dan@example.com>.