问题
I installed GPG from brew.
brew install gpg
It is gnupg2-2.0.30_2.
When I commit, I do get a error message:
You need a passphrase to unlock the secret key for
user: "Max Mustermann (mycomment) <mm@test.de>"
2048-bit RSA key, ID 1111AAAA, created 2017-01-05
error: gpg failed to sign the data
fatal: failed to write commit object
I used the command:
gpg --list-secret-keys | grep ^sec
and it gives me back:
sec 2048R/1111AAAA 2017-01-05
Then I used this command:
git config --global user.signingkey 1111AAAA
commit gives me back the same error message.
How can I solve this problem?
回答1:
If you’re not getting prompted at all for a passphrase (you don’t mention whether you are or not…), the solution may just be to also install a program to facilitate that. The most common is pinentry.
brew install pinentry-mac
So installing that and trying again may get things working. But if not, another thing to do is make sure git
it using/finding the right GPG program. These days you really should be using gpg2
, so if you don’t already have that installed, do:
brew install gnupg2
And then, to tell git
that’s the GPG program want to you, this:
git config --global gpg.program gpg2
At that point, try your commit again and things may just work.
But if not, then try this:
echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
…and then try again.
Note: Per some comments below, in order for this change to take effect, you apparently might need to reboot after making the change.
回答2:
To anybody who is facing this issue on MacOS machines, try this:
brew uninstall gpg
brew install gpg2
brew install pinentry-mac
(if needed)gpg --full-generate-key
Create a key by using an algorithm.- Get generated key by executing:
gpg --list-keys
- Set the key here
git config --global user.signingkey <Key from your list>
git config --global gpg.program /usr/local/bin/gpg
git config --global commit.gpgsign true
- If you want to export your Key to GitHub then:
gpg --armor --export <key>
and add this key to GitHub at GPG keys: https://github.com/settings/keys (with START and END line included)
If the issue still exists:
test -r ~/.bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile
echo 'export GPG_TTY=$(tty)' >> ~/.profile
If the issue still exists:
Install https://gpgtools.org and sign the key that you used by pressing Sign from the menu bar: Key->Sign
If the issue still exists:
Go to: your global .gitconfig
file which in my case is at: /Users/gent/.gitconfig
And modify the .gitconfig file (please make sure Email and Name are the same with the one that you have created while generating the Key):
[user]
email = gent@youremail.com
name = Gent
signingkey = <YOURKEY>
[gpg]
program = /usr/local/bin/gpg
[commit]
gpsign = true
gpgsign = true
[filter "lfs"]
process = git-lfs filter-process
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
[credential]
helper = osxkeychain
p.s I took this answer from my previous answer here: gpg failed to sign the data fatal: failed to write commit object [Git 2.10.0]
回答3:
Your question assumes that you actually want to sign your commits. If you don't, the fix is very simple - switch off commit signing:
git config --global commit.gpgsign false
In my case I had inherited some default git config settings which included commit signing.
回答4:
I had the same error message and found that my key was expired. So it might be a good idea to check your key expiration with:
gpg --list-keys
If your key is expired as well you can adjust the expiration date with:
gpg --edit-key <YOUR_KEY>
and then:
gpg> expire
...enter the new expiration date...
gpg> save
来源:https://stackoverflow.com/questions/41502146/git-gpg-onto-mac-osx-error-gpg-failed-to-sign-the-data