gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]

前端 未结 30 1929
难免孤独
难免孤独 2020-11-27 23:55

I followed few articles over the pretty attributes on Git 2.10 release note. Going through which upgraded the git to 2.10.0 and made changes to global .gitconfig

相关标签:
30条回答
  • 2020-11-28 00:46

    My two cents here:

    When you create and add a key to gpg-agent you define something called passphrase. Now that passphrase at some point expires, and gpg needs you to enter it again to unlock your key so that you can start signing again.

    When you use any other program that interfaces with gpg, gpg's prompt to you to enter your passphrase does not appear (basically gpg-agent when daemonized cannot possibly show you the input dialog in stdin).

    One of the solutions is gpg --sign a_file.txt then enter the passphrase that you have entered when you created your key and then everything should be fine (gpg-agent should automatically sign)

    See this answer on how to set longer timeouts for your passphrase so that you do not have to do this all the time.

    Or you can completely remove the passphrase with ssh-keygen -p

    Edit: Do a man gpg-agent to read some stuff on how to have the above happen automatically and add the lines:

    GPG_TTY=$(tty)
    export GPG_TTY
    

    on your .bashrc if you are using bash(this is the correct answer but I am keeping my train of thought above as well)

    0 讨论(0)
  • 2020-11-28 00:46

    The git trace was very revealing for my situation...

       GIT_TRACE=1 git commit -m "a commit message"
    
       13:45:39.940081 git.c:344               trace: built-in: git commit -m 'a commit message'
       13:45:39.977999 run-command.c:640       trace: run_command: gpg --status-fd=2 -bsau 'full name <your-email@domain.com>'
       error: gpg failed to sign the data
       fatal: failed to write commit object
    

    I needed to generate an initial key per the format that git was checking against. It's best to copy the value passed to -bsau above in the logs as is and use below.

    So it becomes,

       gpg --quick-generate-key "full name <your-email@domain.com>"
    

    Then it worked.

    Hope that helps.

    0 讨论(0)
  • 2020-11-28 00:46

    I had a similar issue with the latest Git sources (2.12.2) built along with the latest sources of all its dependencies (Zlib, Bzip, cURL, PCRE, ReadLine, IDN2, iConv, Unistring, etc).

    It turns out libreadline was giving GnuPG problems:

    $ gpg --version
    gpg: symbol lookup error: /usr/local/lib/libreadline.so.7: undefined symbol: UP
    

    And of course, trying to get useful information from Git with -vvv failed, so the failure was a mystery.

    To resolve the PGP failure due to ReadLine, follow the instructions at Can't update or use package manager -- gpg error:

    In terminal:

    ls /usr/local/lib
    

    there was a bunch of readline libs in there (libreadline.so.BLAH-BLAH) so i:

    su
    mkdir temp
    mv /usr/local/lib/libreadline* temp
    ldconfig
    
    0 讨论(0)
  • 2020-11-28 00:46

    I am on Ubuntu 18.04 and got the same error, was worried for weeks too. Finally realized that gpg2 is not pointing towards anything. So simply run

    git config --global gpg.program gpg
    

    And tada, it works like charm.

    Your commits will now have verified tag with them.

    0 讨论(0)
  • 2020-11-28 00:46

    For me, brew had updated the gnupg or gpg so all I had to do to fix this is.

    brew link --overwrite gnupg
    

    That linked the gpg to the right place, as I can confirm via which gpg and everything worked after that.

    0 讨论(0)
  • 2020-11-28 00:47

    If everything fails, use GIT_TRACE=1 to try and see what git is actually doing:

    $ GIT_TRACE=1 git commit -m "Add page that always requires a logged-in user"
    20:52:58.902766 git.c:328               trace: built-in: git 'commit' '-vvv' '-m' 'Add page that always requires a logged-in user'
    20:52:58.918467 run-command.c:626       trace: run_command: 'gpg' '--status-fd=2' '-bsau' '23810377252EF4C2'
    error: gpg failed to sign the data
    fatal: failed to write commit object
    

    Now run the failing command manually:

    $ gpg -bsau 23810377252EF4C2
    gpg: skipped "23810377252EF4C2": Unusable secret key
    gpg: signing failed: Unusable secret key
    

    Turns out, my key was expired, git was not to blame.

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