Gpg: public key decryption failed: Permission denied gpg: decryption failed: No secret key

Hi, we are facing this error while working with gpg;

The secret key imports successfully, private key was imported with this option

gpg -vv --pinentry-mode loopback --import keyprivate.key

This key was created by an individual user and exported for a generic user. Encryption is working, but decryption fails. I tried many options, but none of them is working. Secret keys are showing while listed with a generic user.

Error while decryption: Gpg: public key decryption failed: Permission denied gpg: decryption failed: No secret key

I have not faced this issue with the previous gpg version 2.0X

What error message do you get when importing the private key?

Sorry, there is a typo in the previous post. I have corrected it in the post. Key import is not an issue. While doing decryption: Gpg: public key decryption failed: Permission denied gpg: decryption failed: No secret key : using this command : gpg --batch --passphrase “xyz” abc.txt.gpg. Later, I used this command for decryption: gpg --pinentry-mode loopback --output abc1.txt --decrypt abc1.txt.gpg it worked somehow. now gpg --batch --passphrase “xyz” abc1.txt.gpg command is also working. I am not sure what happened suddenly. I have not changed permission etc. gpg-agent cached your passphrase after a successful operation (import/decrypt) ? Decryption issue will come again with gpg --batch --passphrase “xyz” abc1.txt.gpg ?

Hi @sunilshri85,
from your last message I am not sure that is working and what is not working now for you.

One general rule is: If you need to fully automate the decryption, you can use a private key without passphrase and then secure your operating environment accordingly. This way you avoid piping in a passphrase via --passphrase-fd or similiar.

Does this hint help you?

[quote=“sunilshri85, post:3, topic:7108”]
Sorry, there is a typo in the previous post. I have corrected it in the post. Key import is not an issue. While doing decryption: Gpg: public key decryption failed: Permission denied gpg: decryption failed: No secret key : using this command : gpg --batch --passphrase “xyz” abc.txt.gpg.[/quote]

You need to add --pinentry-mode loopback. So in total:

gpg --pinentry-mode loopback --batch --passphrase passphrase --decrypt test.txt.gpg

Instead of --passphrase, better use one of these options:

  • ./program_outputting_password | gnupg --pinentry-mode loopback --batch --passphrase-fd 0 ...
  • cat hidden-password-file | gnupg --pinentry-mode loopback --batch --passphrase-file hidden-password-file ...

This willl prevent that the password is visible in the process list.

The password was likely being cached.