Skip to content

Instantly share code, notes, and snippets.

@AnjaneyuluBatta505
Forked from cezaraugusto/gpg_fix.txt
Created September 7, 2021 08:32
Show Gist options
  • Save AnjaneyuluBatta505/e072f5a7ef303889317f7d20e510be3e to your computer and use it in GitHub Desktop.
Save AnjaneyuluBatta505/e072f5a7ef303889317f7d20e510be3e 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment