Git error - gpg failed to sign data

前端 未结 26 1454
遇见更好的自我
遇见更好的自我 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:44

    I am using it. It has support for zsha and works on Windows Subsystem for Linux:

    export GPG_TTY=$(tty)
    
    0 讨论(0)
  • 2020-12-07 07:45

    I had to fix the gpg.program to the absolute path to gpg:

    git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
    

    I am using Windows with cygwin.

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

    If you are using smart card/yubikey to store your GPG key and you set the signkey of git config by the key stored in the card (and all the answer above seem not to resolve your issue), your blocked PIN of the card might be the root cause of this issue.

    To check the blocked PIN:

    gpg --card-status
    

    If the counter is similar to

    Reader ...........: Yubico YubiKey
    PIN retry counter : 3 0 3
    

    Then your PIN is blocked (after 3 unsuccessful tries).

    To unblock the PIN:

    gpg --card-edit
    gpg/card> admin
    Admin commands are allowed
    
    gpg/card> passwd
    gpg: OpenPGP card no. … detected
    
    1 - change PIN
    2 - unblock PIN
    3 - change Admin PIN
    4 - set the Reset Code
    Q - quit
    
    Your selection? 2
    PIN unblocked and new PIN set.
    
    1 - change PIN
    2 - unblock PIN
    3 - change Admin PIN
    4 - set the Reset Code
    Q - quit
    
    Your selection? q
    
    0 讨论(0)
  • 2020-12-07 07:46

    Somehow your git is configured to GPG sign every commit. Signing with GPG isn't required to commit or push using git. It's likely giving the error because your gpg signing mechanism isn't configured yet.

    If you're new to git, try to get it working first without GPG signing at first, then add signing in later if you really need it.

    You can verify how your git is configured with regards to gpg by doing:

    git config -l | grep gpg
    

    Which may produce zero or more lines, including:

    commit.gpgsign=true
    

    If "commit.gpgsign" is true, then you have gpg signing enabled. Disable it with:

    git config --global --unset commit.gpgsign
    

    Then try to run your commit again. It should now run without gpg signing. After you get the basic git working, then you should try adding gpg signing back to the mix.

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

    This worked for me on ubuntu 18.04

    Check your gpg key

    gpg -K --keyid-format LONG
    

    if you get a blank response ,generate a GPG key

    gpg --generate-key
    

    rerun the first command, you should get an output as:

    sec   rsa3072/95A854E0593B3214 2019-05-06 [SC] [expires: 2021-05-05]
          AF2F7514568DC26B0EB97B9595A854E0593B74D8
    uid                 [ultimate] yourname<your_email>
    ssb   rsa3072/EFD326E6C611117C 2019-05-06 [E] [expires: 2021-05-05]
    

    set git singing key

    git config --global user.singingkey 95A854E0593B3214
    

    then you are good to go! (--global is optional)

    Alternatively if you dont mind signing with your ssh key

    git config commit.gpgsign false
    

    note that this is not recommended due to a security issue according to this question here and here

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

    Same error can also be caused when you have expired key in your git config.

    Please check the content of cat .git/config and look for signingkey value and check if it is expired. If yes update it with the new one.

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