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
Issue: Disabled loopback pinentry mode
To solve the problem, you need to enable loopback pinentry mode in ~/.gnupg/gpg.conf:
cat <<'EOF' >> ~/.gnupg/gpg.conf
use-agent
pinentry-mode loopback
EOF
And also in ~/.gnupg/gpg-agent.conf (create the file if it doesn't already exist):
cat <<'EOF' >> ~/.gnupg/gpg-agent.conf
allow-loopback-pinentry
EOF
Then restart the agent with
echo RELOADAGENT | gpg-connect-agent
and you should be good to go!
Source
What solved it for me was making sure the key's name matched my git user name. I assume the emails have to match too. This might have to do with me using GPG KeyChain on my Mac. Not sure.
I thought I was naming the key when I filled this out, but I guess it was asking for my name (git user name).
In my case, I had to match the name stored in GitHub settings to the name and comment of the key.
So if gpg --list-keys
returns uid [ultimate] Joe Blogs (fancy comment) <email@example.com>
your name in .gitconfig should be Joe Blogs (fancy comment)
.
Initially, I had my name set as Joe Blogs
and GPG would not find my key and show the "no secret key" error in strace
. Unfortunately, that error didn't appear without strace
and one would get the generic
error: gpg failed to sign the data
fatal: failed to write commit object
Git needs to know which key it is signing with.
After you have setup GPG, gpg-agent, and your gpg.conf files (see this guide), you need to run
git config --global user.signingkey EB11C755
Obviously, replace the public key at the end with your own. If you want every commit to be signed by default, use
git config --global commit.gpgsign true
In my case, this error occurred when running git commit
on a small tmux
window that was not able to fit the passphrase prompt.
$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
test
gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small
In my case, I had mixed gpg configuration and smimesign configuration given in the commit signing documentation here: https://help.github.com/en/github/authenticating-to-github/telling-git-about-your-signing-key
After working on it for hours, I found the best way to correct it was unset everything related to gpg, and reconfiguring gpg.
As mentioned in @Jason Thrasher's answer, find all the git config related to gpg using:
git config -l | grep gpg
Then unset everything golablly as well as locally using:
git config --global --unset <config_name>
git config --local --unset <config_name>
Then reconfigure following the official documentation given above. Hope this helps.