Git error - gpg failed to sign data

前端 未结 26 1453
遇见更好的自我
遇见更好的自我 2020-12-07 07:19

I just started using git and I install git and gpg via homebrew. For some reason, I get this error when i do git commit I looked at so many other stackoverflow

相关标签:
26条回答
  • 2020-12-07 07:48

    I experienced this problem after upgrading to gnupg 2.x. It would seen that gpg2 is referencing keys differently: I still had signingkey = ABC98F11 (gpg v1 setting) in my ~/.gitconfig. The key identifiers for gpg2 are longer. Look them up with gpg --list-secret-keys

    0 讨论(0)
  • 2020-12-07 07:50

    If you had your pinentry and gpg setup up before, and it stopped working out of nowhere:

    Check if your gpg works:

    echo "test" | gpg --clearsign
    

    If it says gpg: signing failed: No pinentry, just restart the gpg daemon client, which gets stuck from time to time:

    gpgconf --kill gpg-agent
    

    Now it should be working:

    echo "test" | gpg --clearsign
    
    0 讨论(0)
  • 2020-12-07 07:50

    This will help you to get rid of it

    git config commit.gpgsign false

    0 讨论(0)
  • 2020-12-07 07:51

    For troubleshooting, two things to first try:

    • run git config --global gpg.program gpg2, to make sure git uses gpg2 and not gpg
    • run echo "test" | gpg2 --clearsign, to make sure gpg2 itself is working

    If that all looks all right, one next thing to try:

    • run brew install pinentry to ensure you have a good tool installed for passphrase entry

    If after that install and you re-try git commit and still get the "failed to sign the data" error:

    • run gpgconf --kill gpg-agent to kill any running agent that might be hung

    If that says gpgconf isn’t installed or doesn’t have a --kill option, you might try this:

    1. cp ~/.gnupg ~/.gnupg-GOOD to save a copy of your ~/.gnupg to revert to later if needed
    2. brew install gnupg21 to install GnuPG 2.1

    The reason for saving a copy of your ~/.gnupg dir is that GnuPG 2.1 potentially creates/changes some key data in way that isn’t backward-compatible with GnuPG 2.0 and earlier, so if you want to go back later, you can do mv ~/.gnupg ~/.gnupg21 && mv ~/.gnupg-GOOD ~/.gnupg.


    Otherwise there are some basic steps to run to check you’ve got a working GnuPG environment:

    • run gpg2 -K --keyid-format SHORT, to check that you have at least one key pair

    If the output of that shows you have no secret key for GnuPG to use, then you need to create one:

    • run gpg2 --gen-key, to have GnuPG walk you through the steps for creating a key pair

    If you get an error message saying “Inappropriate ioctl for device”, do this:

    • run export GPG_TTY=$(tty) and/or add that to your ~/.bashrc or ˜/.bash_profile
    0 讨论(0)
  • 2020-12-07 07:52

    I had this issue just now when VSCode updated. I figured the GPG agent was hanging, as the command took a good few seconds to run before erroring out. Running gpgconf --kill gpg-agent reset that and fixed it for me.

    0 讨论(0)
  • 2020-12-07 07:55

    For me this error started to occur with git tag -s on Debian GNU/Linux when I switched from pinentry-gnome3 to pinentry-curses (using update-alternatives --config pinentry) for easier remote access. It only occurred with git tag -s, not with gpg (e.g. gpg --clearsign) itself.

    The sole change necessary to get it working again in this case was to add export GPG_TTY=$(tty) to my shell startup files.

    I though didn't get the “Inappropriate ioctl for device” error message mentioned as indicator for this fix in another answer to this question.

    Note: Since the cause for getting this error was a completely different one than for those who suggested export GPG_TTY=$(tty) before (usually as a side hint) in other answers to this question, I decided this question needs another answer which mentions that export GPG_TTY=$(tty) may be the main fix and sole thing necessary in some cases.

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