git - gpg onto mac osx: error: gpg failed to sign the data git - gpg onto mac osx: error: gpg failed to sign the data git git

git - gpg onto mac osx: error: gpg failed to sign the data


If you’re not getting prompted at all for a passphrase, the solution may just be to 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.

And you may also need to stop gpg-agent:

gpgconf --kill gpg-agent

You don’t need to manually restart it — it will get restarted automatically when it’s needed.

Note: Some comments below mention needing to reboot after making changes — but it seems likely the only effect that has it is to cause gpg-agent to be restarted. So manually killing gpg-agent as described above should be sufficient.


To anybody who is facing this issue on MacOS machines, try this:

  1. brew uninstall gpg
  2. brew install gpg2
  3. brew install pinentry-mac (if needed)
  4. gpg --full-generate-key Create a key by using an algorithm.
  5. Get generated key by executing: gpg --list-keys
  6. Set the key here git config --global user.signingkey <Key from your list>
  7. git config --global gpg.program /usr/local/bin/gpg
  8. git config --global commit.gpgsign true
  9. 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/.gitconfigAnd 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