gpg decryption fails with no secret key error

后端 未结 9 659
一生所求
一生所求 2020-12-13 17:48

I have a gpg .key file that is used as passphrase for decrypting a .dat.pgp file. The encrypted .data.pgp file gets successfully decrypted on one server with same .key file

相关标签:
9条回答
  • 2020-12-13 18:21

    I got the same error when trying to decrypt the key from a different user account via su - <otherUser>. (Like jayhendren suggests in his answer)

    In my case, this happened because there would normally start a graphical pinentry prompt so I could enter the password to decrypt the key, but the su -ed to user had no access to the (graphical) X-Window-System that was currently running.

    The solution was to simply issue in that same console (as the user under which the X Server was currently running):

    xhost +local:

    Which gives other local users access to the currently running (local) X-Server. After that, the pinentry prompt appeared, I could enter the password to decrypt the key and it worked...

    Of course you can also forward X over ssh connections. For this look into ssh's -X parameter (client side) and X11Forwarding yes (server side).

    0 讨论(0)
  • 2020-12-13 18:22

    Following this procedure worked for me.

    To create gpg key. gpg --gen-key --homedir /etc/salt/gpgkeys

    export the public key, secret key, and secret subkey.

    gpg --homedir /etc/salt/gpgkeys --export test-key > pub.key
    gpg --homedir /etc/salt/gpgkeys --export-secret-keys test-key > sec.key
    gpg --homedir /etc/salt/gpgkeys --export-secret-subkeys test-key > sub.key
    

    Now import the keys using the following command.

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

    Verify if the keys are imported.

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

    Create a sample file.

    echo "hahaha" > a.txt

    Encrypt the file using the imported key

    gpg --encrypt --sign --armor -r test-key a.txt

    To decrypt the file, use the following command.

    gpg --decrypt a.txt.asc

    0 讨论(0)
  • 2020-12-13 18:24

    When migrating from one machine to another-

    1. Check the gpg version and supported algorithms between the two systems.

      gpg --version

    2. Check the presence of keys on both systems.

      gpg --list-keys

      pub 4096R/62999779 2020-08-04 sub 4096R/0F799997 2020-08-04

      gpg --list-secret-keys

      sec 4096R/62999779 2020-08-04 ssb 4096R/0F799997 2020-08-04

    Check for the presence of same pair of key ids on the other machine. For decrypting, only secret key(sec) and secret sub key(ssb) will be needed.

    If the key is not present on the other machine, export the keys in a file from the machine on which keys are present, scp the file and import the keys on the machine where it is missing.

    Do not recreate the keys on the new machine with the same passphrase, name, user details as the newly generated key will have new unique id and "No secret key" error will still appear if source is using previously generated public key for encryption. So, export and import, this will ensure that same key id is used for decryption and encryption.

    gpg --output gpg_pub_key --export <Email address>
    gpg --output gpg_sec_key --export-secret-keys <Email address>
    gpg --output gpg_sec_sub_key --export-secret-subkeys <Email address>
    
    gpg --import gpg_pub_key
    gpg --import gpg_sec_key
    gpg --import gpg_sec_sub_key
    
    0 讨论(0)
  • 2020-12-13 18:31

    You can also sometimes get this error if you try to decrypt a secret while su-ed to a different user on a system with GPG 2.x installed. This bug has been reported against RHEL 6 but there is no fix available; apparently this is due to some design decisions in GPG 2.x. One workaround suggested in the bug report is to run the decryption inside of a tmux or screen session. More reading here.

    0 讨论(0)
  • 2020-12-13 18:33

    I just ran into this issue, on the gpg CLI in Arch Linux. I needed to kill the existing "gpg-agent" process, then everything was back to normal ( a new gpg-agent should auto-launch when you invoke the gpg command, again; ...).

    • edit: if the process fails to reload (e.g. within a minute), type gpg-agent in a terminal and/or reboot ...
    0 讨论(0)
  • This error will arise when using the utility pass if the terminal window is too small!

    Just make the terminal window a few lines taller.

    Very confusing.

    0 讨论(0)
提交回复
热议问题