Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@bobbysiagian00 bobbysiagian00 commented Jul 29, 2019

i highly suggest this gist , everything goes well now

@maoroam

This comment has been minimized.

Copy link

@maoroam maoroam commented Dec 16, 2019

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

@orome

This comment has been minimized.

Copy link

@orome orome commented Jan 14, 2020

QFT

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

@jplew

This comment has been minimized.

Copy link

@jplew 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

This comment has been minimized.

Copy link

@Shosta 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

This comment has been minimized.

Copy link

@umeshblader3 umeshblader3 commented Apr 10, 2020

Thanks @Shosta. It solved me

@rwhitley

This comment has been minimized.

Copy link

@rwhitley rwhitley commented Jun 8, 2020

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

@colinschoen

This comment has been minimized.

Copy link

@colinschoen colinschoen commented Jun 10, 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).

Thanks this fixed for me as well.

@longjons

This comment has been minimized.

Copy link

@longjons longjons commented Jun 21, 2020

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

@yeirr

This comment has been minimized.

Copy link

@yeirr yeirr commented Jun 27, 2020

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

@escandihub

This comment has been minimized.

Copy link

@escandihub escandihub commented Sep 17, 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).

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

This comment has been minimized.

Copy link

@alaydeliwala alaydeliwala commented Sep 28, 2020

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

@anuragmob

This comment has been minimized.

Copy link

@anuragmob anuragmob commented Oct 19, 2020

gpgconf --kill gpg-agent

Worked!

@gfortil

This comment has been minimized.

Copy link

@gfortil gfortil commented Feb 4, 2021

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

@inoas

This comment has been minimized.

Copy link

@inoas inoas commented Jun 14, 2021

gpgconf --kill gpg-agent

worked for me after upgrading to big sur

@dturnercbre

This comment has been minimized.

Copy link

@dturnercbre dturnercbre commented Jul 12, 2021

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

@haifahrul

This comment has been minimized.

Copy link

@haifahrul haifahrul commented Jul 15, 2021

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

This comment has been minimized.

Copy link

@longility longility commented Sep 3, 2021

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

This comment has been minimized.

Copy link

@shiretu shiretu commented Sep 8, 2021

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

@SameeraMadushan

This comment has been minimized.

Copy link

@SameeraMadushan SameeraMadushan commented Sep 11, 2021

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

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