4

I cannot seem to get gnupg to decrypt files encrypted with my keys. I've tried migrating my secret key from an old laptop to a new one, and I keep getting the same error:

gpg: decryption failed: No secret key

I tried exporting my public, secret, and subkeys from my old laptop as follows:

gpg --export MYKEYID > pub.key
gpg --export-secret-keys MYKEYID > sec.key
gpg --export-secret-subkeys MYKEYID > sub.key

I then copied them to my new laptop, and imported them as follows:

gpg --import pub.key
gpg --import sec.key
gpg --import sub.key

Then I edited the key to give it ultimate trust:

gpg --edit-key MYKEYID

gpg> trust
...
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

yet no matter what, it fails to decrypt:

gpg --decrypt -v encryptedfile.gpg
gpg: public key is E78E22A13ED8B15D
gpg: encrypted with ELG key, ID E78E22A13ED8B15D
gpg: decryption failed: No secret key

Version on old laptop:

gpg --version
gpg (GnuPG) 2.1.21
libgcrypt 1.7.6

Version on new laptop:

gpg --version
gpg (GnuPG/MacGPG2) 2.2.3
libgcrypt 1.8.1
  • Does gpg --list-keys show your private key? – Peter Harmann Apr 29 '18 at 20:57
  • 3
    Does --list-secret-keys show your secret key? Maybe you need to set (even though the manpage says otherwise) allow-secret-key-import. Also: Voting to migrate to SU. – Tobi Nary Apr 29 '18 at 21:42
2

This was entirely my fault. I'm not sure what happened, but the file I was trying to decrypt was not encrypted by my key. I tried a different file and it worked.

I'm not sure how that happened, but testing the same file on the old machine first would have saved me a ton of time :).

1

I randomly started getting the error

gpg: decryption failed: No secret key

as well, when attempting to decrypt files. Strangely, GPG was telling me that the files were encrypted with a different key ID than my own (despite identifying my name and the date of the key’s creation correctly). I restarted my computer and the problem went away.

I’m guessing there is a bug where some bit can get misaligned in the GPG daemon’s memory, and then it will need restarting.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.