gpg: decryption failed: No secret key

  • 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?

    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.

  • stantonk

    stantonk Correct answer

    3 years ago

    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 :).

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used