14
votes

I am not able to decrypt my file without secret key. I know this question is asked on this before, solutions on this question did not help me.

This is my problem's scenario. This error I receive on command prompt while using --decrypt command.

gpg: decryption failed: No secret key

I have public key and a passphrase with me. I have used following commands to check if there is secret key or not.

• gpg --list-secret-keys

• gpg --list-keys

Both the above commands returned blank result(no error). so I decided to import public key with --import .

• gpg --import "C:\PATH\TO_MY_PUBLIC_KEY"

After --import command I can see public is imported. I could not find the way to deal with secret key. Is there any way I can find secret key or create new secret key.

8

8 Answers

15
votes

I also received blank output from the same 2 commands:

gpg --list-secret-keys
gpg --list-keys

I had reason to suspect this was to do with recent changes to the ~/.gnupg/pubring.kbx file, which lead me to run the following 2 commands to re-import missing keys:

Re-import missing secret keys:

gpg --import < ~/.gnupg/secring.gpg

Re-import missing public keys:

gpg --import < ~/.gnupg/pubring.gpg
4
votes

Very short version: you can't decrypt without the secret key.

GnuPG asks for the secret key (often used as synonym for private key if you read that somewhere), so the message was encrypted using public/private key cryptography. You cannot decrypt the message using the public key, that's the basic principle behind public/private key cryptography. Secret keys can be protected with a passphrase, that's why you might have a passphrase (although you miss the key).

Ask for the private key if you are required to decrypt the message, or ask the sender to encrypt using symmetric cryptography and share the passphrase with you.

3
votes

This message can also happen if your pinentry program isn't working properly, and thus gpg can't get the passphrase to unlock the decryption key. This has happened to me a couple of times. If this is the case, gpg -d -v will appear to select the correct key and then just hang for a while before giving up. This is it waiting for the pinentry that never actually returns.

The steps depend on your specific environment, but checking (or creating) the pinentry-program option in ~/.gnupg/gpg-agent.conf is a good place to start. In my case (on OS X with Homebrew-installed gpg and pinentry-mac) I had to create that file with the following contents:

pinentry-program /usr/local/bin/pinentry-mac

You may need to adjust as needed for whatever your preferred pinentry program is.

3
votes

I had the same error but with a different solution to it, this was on OSX but I assume it will be similar on others.

The gpg-agent seemed to be the culprit as I realised that I never got the pinentry question for one of my keys. Killing it with gpgconf --kill gpg-agent solved that. And with the first call that needs it the gpg-agent will start automatically. And indeed the pinentry appeared and all was fine again.

0
votes

In the event you import & then trust (ultimately) and can see the keys using gpg --list-secret-keys but when you go to decrypt it tells you it can't find the secret key, add the --batch to your decrypt command.

0
votes

In my case, both gpg (1.x) and gpg2 were installed on the system, and gpg 1.x doesn't have support for my ed25519 keys.

You'll know which algorithms are supported by looking at the version, grep for Pubkey

/usr/bin/gpg --version 
/usr/bin/gpg2 --version

If thats the case, try gpg2 --list-secret-keys

If that works, add an alias to .bashrc and symlink into ~/bin (for git)

echo "alias gpg='gpg2'" >> ~/.bashrc
ln -s /usr/bin/gpg2 $HOME/bin/gpg
. ~/.bashrc

Then, gpg --list-secret-keys output wasn't empty anymore.

Maybe it doesn't solve OP's issue, but hope this helps someone.

0
votes

you can ignore the error using: export GPG_TTY=$(tty)

0
votes

In my case my gpg key had password and when I entered git-crypt unlock in vscode terminal which had a limited width and height it outputs

gpg: decryption failed: No secret key
git-crypt: GPG error: Failed to decrypt

But when I try the same command on a full terminal windows it works like charm and prompts for getting password and so on.