Skip to content

Instantly share code, notes, and snippets.

@cezaraugusto
Last active November 3, 2023 17:03
Show Gist options
  • Star 45 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save cezaraugusto/2c91d141ddec026753051ffcace3f1f2 to your computer and use it in GitHub Desktop.
Save cezaraugusto/2c91d141ddec026753051ffcace3f1f2 to your computer and use it in GitHub Desktop.
fixing `gpg failed to sign data` error on macOS
For troubleshooting, two things to first try:
run `git config --global gpg.program gpg2`, to make sure git uses gpg2 and not gpg
run `echo "test" | gpg2 --clearsign`, to make sure gpg2 itself is working
If that all looks all right, one next thing to try:
run `brew install pinentry` to ensure you have a good tool installed for passphrase entry
If after that install and you re-try git commit and still get the "failed to sign the data" error:
run `gpgconf --kill gpg-agent` to kill any running agent that might be hung
If that says gpgconf isn’t installed or doesn’t have a `--kill` option, you might try this:
`cp ~/.gnupg ~/.gnupg-GOOD` to save a copy of your `~/.gnupg` to revert to later if needed
`brew install gnupg21` to install `GnuPG 2.1`
The reason for saving a copy of your `~/.gnupg` dir is that GnuPG 2.1 potentially creates/changes some key data in way that isn’t backward-compatible with GnuPG 2.0 and earlier, so if you want to go back later, you can do `mv ~/.gnupg ~/.gnupg21 && mv ~/.gnupg-GOOD ~/.gnupg`.
Otherwise there are some basic steps to run to check you’ve got a working GnuPG environment:
run `gpg2 -K --keyid-format SHORT`, to check that you have at least one key pair
If the output of that shows you have no secret key for GnuPG to use, then you need to create one:
run `gpg2 --gen-key`, to have GnuPG walk you through the steps for creating a key pair
source: https://stackoverflow.com/a/41054093/4902448
@bobbysiagian00
Copy link

i highly suggest this gist , everything goes well now

@maoroam
Copy link

maoroam commented Dec 16, 2019

need to change from 'brew install gnupg21' to 'brew install gnupg2'

@orome
Copy link

orome commented Jan 14, 2020

QFT

run gpgconf --kill gpg-agent to kill any running agent that might be hung

@jplew
Copy link

jplew commented Jan 25, 2020

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

@Shosta
Copy link

Shosta commented Jan 28, 2020

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

This solved my problem as well.
Thanks for the tip.

@umeshblader3
Copy link

Thanks @Shosta. It solved me

@rwhitley
Copy link

rwhitley commented Jun 8, 2020

This (the gpgconf --kill gpg-agent command) worked for me. Thank you.

@colinschoen
Copy link

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

Thanks this fixed for me as well.

@longjons
Copy link

Hey Thanks orome your suggested fix
worked out Gr8 for me too
:-)

@yeirr
Copy link

yeirr commented Jun 27, 2020

Great concise walk-through, quickfix solved it on ubuntu 18.04

@escandihub
Copy link

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

  • Thanks this fixed. 🔥
    to add, if it helps somebody don't forget to restart the thermian lol

@alaydeliwala
Copy link

gpgconf --kill gpg-agent was what worked for me

@anuragmob
Copy link

gpgconf --kill gpg-agent

Worked!

@gfortil
Copy link

gfortil commented Feb 4, 2021

gpg --list-keys
git config --global user.signingkey [my pub hash key]
worked for me

@inoas
Copy link

inoas commented Jun 14, 2021

gpgconf --kill gpg-agent

worked for me after upgrading to big sur

@dturnercbre
Copy link

Thank you for this. I'm a returning Mac user and this was causing me some headaches after the Big Sur upgrade.

@haifahrul
Copy link

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

  • Thanks this fixed. 🔥
    to add, if it helps somebody don't forget to restart the thermian lol

worked for me. My mac OS Big Sur.

Thanks all

@longility
Copy link

I upgraded brew and I got

gpg: signing failed: No pinentry
gpg: [stdin]: clear-sign failed: No pinentry

gpgconf --kill gpg-agent worked for me too. Thanks for the tips!

@shiretu
Copy link

shiretu commented Sep 8, 2021

killed gpg agent and also exported that env var. Still no joy...

@SameeraMadushan
Copy link

In my case (zsh on MacOS Catalina), all I needed to do to fix this was add to this to my .zshrc: export GPG_TTY=$(tty).

  • Thanks this fixed. 🔥
    to add, if it helps somebody don't forget to restart the thermian lol

This works!
export GPG_TTY=$(tty) then source ~/.zshrc

@chiefmikey
Copy link

stack overflow thread has nothing on this gist!!!

@felipealfonsog
Copy link

In Debian 10, worked out well:

export GPG_TTY=$(tty)
source ~/.bashrc

@nelsonc24
Copy link

the gpgconf --kill gpg-agent command saved my day Thank you!!!!.

@ddwolf
Copy link

ddwolf commented Jun 20, 2022

for me, remove the gpgsign: true in git config --global -e works, lol

@2-tran
Copy link

2-tran commented Nov 1, 2022

Thank you! It worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment