How do I specify a private key for decrypting in gpg

I use gpg on ubuntu and I have two keyrings I want to decrypt a message with my second private key but gpg uses the first key for decryption. How I specify private key for decryption? Thanks!

19

1 Answer

You should be able to use --keyring <file> and --no-default-keyring.

From the gpg man page:

 --keyring file Add file to the current list of keyrings. If file begins with a tilde and a slash, these are replaced by the $HOME directory. If the filename does not contain a slash, it is assumed to be in the GnuPG home directory ("~/.gnupg" if --homedir or $GNUPGHOME is not used). Note that this adds a keyring to the current list. If the intent is to use the specified keyring alone, use --keyring along with --no-default-keyring.

It does seem odd this would be necessary. Perhaps the encrypted file does not specify the recipient properly or at all?
If it is anonymous you might need to use --try-all-secrets also.

7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like