Skip to content

Instantly share code, notes, and snippets.

@paolocarrasco
Last active May 3, 2024 15:20
Show Gist options
  • Save paolocarrasco/18ca8fe6e63490ae1be23e84a7039374 to your computer and use it in GitHub Desktop.
Save paolocarrasco/18ca8fe6e63490ae1be23e84a7039374 to your computer and use it in GitHub Desktop.
How to understand the `gpg failed to sign the data` problem in git

Problem

You have installed GPG, then tried to commit and suddenly you see this error message after it:

error: gpg failed to sign the data
fatal: failed to write commit object

Debug

For understanding what's going on, first check what git is doing, so add GIT_TRACE=1 at the beginning of the command you used before (git commit or git rebase):

GIT_TRACE=1 git commit

With that you can see what GPG is doing: Probably you will see something like this

10:37:22.346480 run-command.c:637       trace: run_command: gpg --status-fd=2 -bsau <your GPG key>

(Check if your GPG key is correct)

Execute that gpg command again in the command line:

gpg --status-fd=2 -bsau <your GPG key>

👆🏻 With this now you could see what happened in detail!

Solutions

We can have many problems, but I list what I found:

  1. It could be that the GPG key was expired: https://stackoverflow.com/a/47561300/532912

  2. Another thing could be that the secret key was not set properly (In my case the message said gpg: signing failed: No secret key as it can be see in the image below). image It means that is not finding the key that was set. You would need to set up the GPG key in Git (again):

    • List the secret keys available in GPG.
    gpg --list-secret-keys --keyid-format=long
    • Copy your key
    • Set your key for your user in git
    git config --global user.signingkey <your key>
  3. Another popular solution that could help was shared here by @NirajanMahara: https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374?permalink_comment_id=3767413#gistcomment-3767413

  4. You can see in the thread of this gist other ways to find the solution to other problems. I recommend to read the Github guide for signing commits with GPG.

Hope it helps!

@chevyphillip
Copy link

@justinbalaguer solution worked for me here.

@Kush1406
Copy link

@exostin solution worked for me. Thanks

@mnovozhylov
Copy link

There's another situation:

sec   dsa3072/AAAAAAAAAAAAA 2010-05-05 [SC] [expires: 2030-05-05]
      BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
uid                 [ultimate] Author Name <author-email@domain.com>

While GitHub documentation operates with AAAAAAAAAAAAA in sections when you need to create and register the key in GPG, git requires BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, i.e. git config --global user.signingkey BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, instead of git config --global user.signingkey AAAAAAAAAAAAA

Hopefully, it helps someone.

@ayubov
Copy link

ayubov commented May 26, 2022

I got a case when signing suddenly stopped working. After a long fight nothing has helped except gpgconf --kill gpg-agent

@OliverRC
Copy link

OliverRC commented Jun 7, 2022

If you are on Windows and have used GPG4Win to manage your keys then you need to set the GPG program path.

If you look at where your gpg instance comes from mine looked like

Get-Command gpg | select Source

My gpg path was C:\Program Files (x86)\Gpg4win\..\GnuPG\bin\gpg.exe. That's quite a weird path .

But technically it is the same as "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

So now set GIT to use this path:

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

Essentially it seemed that the gpg program that was being used was different to the one being run when I used gpg on the command line.

@nguyenvulong
Copy link

nguyenvulong commented Jun 11, 2022

if all of the above did not work for you

I got into a slightly different problem, everything up there ALREADY CHECKED, somehow my gpg signing stopped working - and i don't want to restart my server. After digging around i found this log

Some output of systemctl --user status gpg-agent

6월 12 00:50:55 AISRC gpg-agent[17450]: can't connect to the SCdaemon: IPC connect call failed
6월 12 00:50:55 AISRC gpg-agent[17450]: failed to unprotect the secret key: Operation cancelled
6월 12 00:50:55 AISRC gpg-agent[17450]: failed to read the secret key
6월 12 00:50:55 AISRC gpg-agent[17450]: command 'PKSIGN' failed: Operation cancelled <Pinentry>

Note that until this point, it's not about git anymore, it's about gpg and distro-specific issues.

FIXED (the root cause is pinentryscrewed things up)
Create gpg-agent.conf if you don't have one under your home dir and add the line below (pinentry-program /usr/bin/pinentry-curses)


❯ cat  ~/.gnupg/gpg-agent.conf
pinentry-program /usr/bin/pinentry-curses

Then you have to restart gpg-agent by issuing systemctl --user restart gpg-agent and you may want to log-in/out. Make sure to export GPG_TTY=$(tty) and test again. Good luck

Check my write-up here for the summary nguyenvulong/QA#25

@subhendudash02
Copy link

The command

git config --global user.signingkey <your key>

helped me. I forgot to configure the key after generating.
Thanks!

@MedRedha
Copy link

Oh Gosh! You just saved my day 🙏 Thanks a lot @paolocarrasco

@rohitss912
Copy link

@NirajanMahara - Thanks buddy your solution worked for me!

@gmale
Copy link

gmale commented Aug 1, 2022

It could also be due to the fact that you need to enter a password. Run ssh-add before committing.

This was effectively my issue. Somehow running the rebase with GIT_TRACE allowed it to pause and ask for a password (i.e. GIT_TRACE=1 git pull origin master --rebase) and then it all worked. This happened after my computer shut down, which probably explains why the gpg password was required again.

Now that I know GPG was causing this prompt, I followed some of these guides and setup GPG not to prompt for a password any longer.

https://gist.github.com/koshatul/2427643668d4e89c0086f297f9ed2130
https://stackoverflow.com/questions/39780452/prevent-gpg-password-prompt-on-mac
https://unixb0y.de/blog/articles/2019-01/gpg-password-macos-keychain

To test it, I ran the following to verify that it asked me for a prompt. Then, after taking the steps above it stopped asking:

echo test | gpg -e -r myEmail@myemail.com | gpg -d

@victorjatoba
Copy link

Follow the below url to setup signed commit https://help.github.com/en/articles/telling-git-about-your-signing-key

if still getting gpg failed to sign the data fatal: failed to write commit object

this is not issue with git ,this is with GPG follow below steps

  1. gpg --version
  2. echo "test" | gpg --clearsign

if it is showing:

gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device
  1. then use export GPG_TTY=$(tty)
  2. then try again echo "test" | gpg --clearsign in which PGP signature is.

Output:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

test
-----BEGIN PGP SIGNATURE-----

iLMEAQEKAB0WIQS2V0SFHi18psvDbo7uFF+LP7qc1gUCYLjB2QAKCRDuFF+LP7qc
1r5LBACB1m3Lpl21379qAvVamWcn9isdgdg34t34t43t34t34t434yGQHqikxWL7A5
Ls7giKZYscb30o0rkY6I1W9MjBBW96R2pnaYsioFpsf434dfg54rfdgfdgdfgdfpaIoU3k
JKrYxR7yMjqUv0a2jE+97kh+bSuzqwIkMHyikbABI90lY+4OLw==
=UHKx
-----END PGP SIGNATURE-----
  1. git config -l | grep gpg

Output:

commit.gpgsign=true
gpg.program=gpg
tag.gpgsign=true
  1. apply git commit -S -m "initial commit rocketrocketrocketrocket"
  2. or git config --global commit.gpgsign true

https://stackoverflow.com/questions/39494631/gpg-failed-to-sign-the-data-fatal-failed-to-write-commit-object-git-2-10-0/55993078#55993078

It worked for me. Thanks!

@MaxFoton
Copy link

5. git config -l | grep gpg

it also worked for me! thank you!

@dan-developer
Copy link

It seems for every branch I have, I need to execute the export GPG_TTY=$(tty) command before committing.

Is there anyway around this?

It worked for me. Thank you!

@Phrozyn
Copy link

Phrozyn commented Oct 14, 2022

For me the issue is always simply the fact that my vscode terminal window is too small, git needs like half a screen's height and about the width of this comment section for it to surface the GPG prompt, otherwise it errors out and tells you that:

error: gpg failed to sign the data
fatal: failed to write commit object

so I enlarge the window and voila all fixed when I run git commit again.

@Jeff-Tian
Copy link

There's another situation:

sec   dsa3072/AAAAAAAAAAAAA 2010-05-05 [SC] [expires: 2030-05-05]
      BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
uid                 [ultimate] Author Name <author-email@domain.com>

While GitHub documentation operates with AAAAAAAAAAAAA in sections when you need to create and register the key in GPG, git requires BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, i.e. git config --global user.signingkey BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, instead of git config --global user.signingkey AAAAAAAAAAAAA

Hopefully, it helps someone.

It helped me, thanks!

@0xmovses
Copy link

worked for me thank you for this!

@nicat97
Copy link

nicat97 commented Oct 19, 2022

Great! Thanks for your help!

@lucymonie
Copy link

lucymonie commented Oct 24, 2022

Thank you 🙏

@lnasc256
Copy link

thank you

@marionorthvolt
Copy link

I was trying to solve this for 2 days! thanks!

@Lippiece
Copy link

Lippiece commented Dec 2, 2022

  1. then use export GPG_TTY=$(tty)

It also helped to to set it permanently in ~/.profile on Ubuntu (to do so, append export GPG_TTY=$(tty) to the ~/.profile file).

@gcakir
Copy link

gcakir commented Dec 12, 2022

I had the same issue. The output of the command gpg --status-fd=2 -bsau was fine. It turns out my git config in the repo was the problematic. I deleted the [user] and [gpg] entries in .git/config, and then I reconfigured the pgp globally via git config --global gpg.program gpg and git config --global user.signingkey "<my signing key>" once again. Then it worked.

@truemiller
Copy link

4. echo "test" | gpg --clearsign

this worked for me +1

@sankita15
Copy link

I just killed the gpg-agent and started again and it worked for me

killall gpg-agent
gpg-agent daemon

@0x61nas
Copy link

0x61nas commented Jan 12, 2023

thanks, @paolocarrasco

@Honglin-Lu
Copy link

There's another situation:

sec   dsa3072/AAAAAAAAAAAAA 2010-05-05 [SC] [expires: 2030-05-05]
      BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
uid                 [ultimate] Author Name <author-email@domain.com>

While GitHub documentation operates with AAAAAAAAAAAAA in sections when you need to create and register the key in GPG, git requires BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, i.e. git config --global user.signingkey BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, instead of git config --global user.signingkey AAAAAAAAAAAAA

Hopefully, it helps someone.

This solution also works for me. Thank you!

@lfbharat
Copy link

omg I just need to run export GPG_TTY=$(tty)

  1. then use export GPG_TTY=$(tty)

this one worked for me as well.

@LuciNyan
Copy link

LuciNyan commented Feb 1, 2023

3. then use export GPG_TTY=$(tty)

Thank you! it works for me!

@livaper
Copy link

livaper commented Feb 15, 2023

Thank You, @paolocarrasco

@rootsongjc
Copy link

It works. Thank you!

@rahulsaw2003
Copy link

gpg: skipped "D6F50106F5C8A98B": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

I am getting this error since few days, I have regenerated the gpg key many times. but still I am getting this error. What should I do to get rid of this error. Please help as soon as possible.

@rahulsaw2003
Copy link

@exostin
After struggling for hours, I finally get rid of this error.
Thanks man

@kennethsequeira
Copy link

@NirajanMahara lifesaver!
Your solution worked out for me.

@thyarles
Copy link

thyarles commented Mar 8, 2023

I you're on WSL2, maybe this can help:

  • Add those lines to ~/.gnupg/gpg.conf

    use-agent 
    pinentry-mode loopback
    
  • Add this line to ~/.gnupg/gpg-agent.conf

    allow-loopback-pinentry
    

@gauravk-io
Copy link

gauravk-io commented Apr 4, 2023

I was getting the error

gpg: skipped "29D277CEFE65F74E": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

I just need to set the

gpg.program="C:\Program Files (x86)\GnuPG\bin\gpg.exe"

to

gpg.program=gpg

THANKYOU @victorjatoba

@Riessarius
Copy link

This exactly solved my problem. Great thanks! @victorjatoba

@renjujv
Copy link

renjujv commented Apr 24, 2023

@pro-akim
Copy link

pro-akim commented May 2, 2023

Thanks @paolocarrasco, you are awesome

@igorsobot
Copy link

I just killed the gpg-agent and started again and it worked for me

killall gpg-agent
gpg-agent daemon

Yes, sometimes pinentry-mac update brakes gpg-agent

@T410
Copy link

T410 commented May 12, 2023

Additionally, if you are using a mac and you are experiencing an issue, try step number 8: https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key?platform=mac

$ brew install pinentry-mac
$ echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
$ killall gpg-agent

basically, it allows/forces your device to ask the password of the key

@DejavuMoe
Copy link

Super useful, thank you very much!

@ghdcksgml1
Copy link

Thanks :) @T410

@klubi
Copy link

klubi commented Jun 6, 2023

I'm running into similar issue, but It may be a layer deeper.
When I run gpg --status-fd=2 -bsau ... I get

[GNUPG:] PINENTRY_LAUNCHED 106 curses 1.1.0 - - -
gpg: signing failed: Inappropriate ioctl for device
[GNUPG:] FAILURE sign 83918950
gpg: signing failed: Inappropriate ioctl for device

I'm running that in jenkins, and I assume Jenkins is awaiting for passphrase input, but I can't seem to figure out how to sent it to it...

@ferdogan-nex
Copy link

ferdogan-nex commented Jun 12, 2023

This one worked for me. Thanks.

update: I just realised it didn't work.

@thyarles
Copy link

This one worked for me. Thanks.

Which one?

@klubi
Copy link

klubi commented Jun 12, 2023

I'm running into similar issue, but It may be a layer deeper. When I run gpg --status-fd=2 -bsau ... I get

[GNUPG:] PINENTRY_LAUNCHED 106 curses 1.1.0 - - -
gpg: signing failed: Inappropriate ioctl for device
[GNUPG:] FAILURE sign 83918950
gpg: signing failed: Inappropriate ioctl for device

I'm running that in jenkins, and I assume Jenkins is awaiting for passphrase input, but I can't seem to figure out how to sent it to it...

In case anyone runs into same issue, I ended up with below steps to import gpg key to Jenkins and use it to sign commits.

def call(String key_secret, String key_pass_secret, String key_id_secret, String key_grip_secret) {

    withCredentials([file(credentialsId: key_secret, variable: 'GPG_KEY'), 
    string(credentialsId: key_pass_secret, variable: 'GPG_KEY_PASS'),
    string(credentialsId: key_id_secret, variable: 'GPG_KEY_ID'),
    string(credentialsId: key_grip_secret, variable: 'GPG_KEY_GRIP')]) {
        sh """
            gpg --batch --passphrase $GPG_KEY_PASS --import $GPG_KEY
            echo allow-preset-passphrase > /root/.gnupg/gpg-agent.conf
            gpgconf --kill gpg-agent
            gpg-connect-agent -v
            \$(gpgconf --list-dirs libexecdir)/gpg-preset-passphrase --preset --passphrase $GPG_KEY_PASS $GPG_KEY_GRIP
            git config --global commit.gpgsign true
            git config --global user.signingkey $GPG_KEY_ID
            git config --global user.email "<REDACTED>"
            git config --global user.name "<REDACTED>”
        """
        }
}

to get key_grip run gpg —with-keygrip -K

All those shenanigans are caused by lack of tty in Jenkins thus there is no way to interactively input passphrase, so gpg-agent has to receive it as preset.
Killing and connecting back to agent is meant to solve two issues: updates to config, and race condition between agent startup and trying to exec proceeding command.

@ferdogan-nex
Copy link

This one worked for me. Thanks.

Which one?

Never mind, it actually didn't work. I still have the same issue.

@ferdogan-nex
Copy link

I got my issue solved. It was due to git version. Apparently git needs to be above 2.34 for code signing using SSH.

@empeje
Copy link

empeje commented Jun 22, 2023

5. then use export GPG_TTY=$(tty)

It also helped to to set it permanently in ~/.profile on Ubuntu (to do so, append export GPG_TTY=$(tty) to the ~/.profile file).

This save my life 🔥

@gregorywaynepower
Copy link

On Windows 10 machine, I aligned my Local Git instance's username and email to my Github username and email.

The linchpin was taking the second line of gpg --list-secret-keys --keyid-format=LONG (the one below sec) and put that longer code as my user.signingkey for my git config.

@wushingmushine
Copy link

wushingmushine commented Jul 4, 2023

I haven't seen this one yet in thread so in case anyone else encounters it in a small terminal window:

With the same initial error and trace log I ran gpg --status-fd=2 -bsau <your GPG key> but it hung indefinitely with no output.
So I tried echo "test" | gpg --clearsign and got this error:

> echo "test" | gpg --clearsign                                          
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

test
gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small

So turns out you can get this error if your terminal window is too small because the key passphrase box cannot pop up

Thanks @paolocarrasco and @truemiller for the pointers!

@ferpieklo
Copy link

I'm on Windows using the terminal and Gpg4Win (instead of Git Bash), and this helped me solve the gpg: signing failed: No secret key issue.

Make sure that git config gpg.program points to the gpg.exe file from the package by doing the following:

  1. Run where.exe gpg.
  2. If the output returns several executables, locate the one from Gpg4Win (by default, the path is C:\Program FIles (x86)\GnuPG\bin\gpg.exe.
  3. Run git config --global gpg.program <path/to/gpg/from/Gpg4Win>

(source here)

@psavarmattas
Copy link

psavarmattas commented Aug 4, 2023

Thanks so much for this @NirajanMahara . This worked like a charm!

@joespinelli7
Copy link

Thank you! Guided me perfectly through my issue and resolved within minutes :)

@Ahmedntc
Copy link

I you're on WSL2, maybe this can help:

  • Add those lines to ~/.gnupg/gpg.conf
    use-agent 
    pinentry-mode loopback
    
  • Add this line to ~/.gnupg/gpg-agent.conf
    allow-loopback-pinentry
    

Tried pretty much everything and this was what worked for me, thank you!

@meerilahi
Copy link

Thanks
@gauravk-io

@gbdubs
Copy link

gbdubs commented Sep 3, 2023

Thank you!

@OverRevvv
Copy link

Thank you @gauravk-io , I did what you did and resolved the error.

@luiguip
Copy link

luiguip commented Sep 20, 2023

I you're on WSL2, maybe this can help:

* Add those lines to `~/.gnupg/gpg.conf`
  ```
  use-agent 
  pinentry-mode loopback
  ```

* Add this line to `~/.gnupg/gpg-agent.conf`
  ```
  allow-loopback-pinentry
  ```

Thanks, worked on WSL2.

@wlopez30
Copy link

echo "test" | gpg --clearsign

I haven't seen this one yet in thread so in case anyone else encounters it in a small terminal window:

With the same initial error and trace log I ran gpg --status-fd=2 -bsau <your GPG key> but it hung indefinitely with no output. So I tried echo "test" | gpg --clearsign and got this error:

> echo "test" | gpg --clearsign                                          
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

test
gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small

So turns out you can get this error if your terminal window is too small because the key passphrase box cannot pop up

Thanks @paolocarrasco and @truemiller for the pointers!

Yup. This was it for me.
Thank you!

@Carlos-vargs
Copy link

omg I just need to run export GPG_TTY=$(tty)

  1. then use export GPG_TTY=$(tty)

I tried everything and found that comment, you saved me bro

@rosangelysreyes
Copy link

Thank you! It worked for me following each step ❤️

@lehaiquantb
Copy link

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

@after-ephemera
Copy link

Thank you for this!

@sudoAlphaX
Copy link

I'm on Windows using the terminal and Gpg4Win (instead of Git Bash), and this helped me solve the gpg: signing failed: No secret key issue.

Make sure that git config gpg.program points to the gpg.exe file from the package by doing the following:

1. Run `where.exe gpg`.

2. If the output returns several executables, locate the one from Gpg4Win (by default, the path is C:\Program FIles (x86)\GnuPG\bin\gpg.exe.

3. Run `git config --global gpg.program <path/to/gpg/from/Gpg4Win>`

(source here)

This worked for me. Thank you very much.

@babud08
Copy link

babud08 commented Oct 25, 2023

I tried this method and still I'm getting this error while commit my changes.

$ git commit -S -m "workflow files commit"
error: cannot spawn gpg2: No such file or directory
error: gpg failed to sign the data
fatal: failed to write commit object

@sudoAlphaX
Copy link

@babud08 i think you have to set git global config for gpg.program

Find your gpg.exe path by using:
where gpg

and use Git Bash to configure the path
git config --global gpg.program <path>

@szympajka
Copy link

Thank you!

@jrgleason
Copy link

gpg --status-fd=2 -bsau F93581548CDBCCB7
[GNUPG:] KEY_CONSIDERED E4C9A7533D31D43B288E162FF93581548CDBCCB7 2
[GNUPG:] BEGIN_SIGNING H10

and it just hangs there.

@shellheim
Copy link

Dude, I just misspelled user.signingkey as user.signkey

@mojoba
Copy link

mojoba commented Nov 10, 2023

Thank you! My key was wrong. Working now.

@SirPhemmiey
Copy link

What worked for me was setting up program.

  1. first determine the location of your gpg installation. You can use which gpg.
  2. copy the result in the previous step and run the command
git config --global gpg.program "<paste the installation location here>"

@juni37
Copy link

juni37 commented Nov 24, 2023

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

THANK YOU!!! I had to do this and now it's working for me. HUGE KUDOS TO YOU!!

@DimitarNestorov
Copy link

On my Mac all I had to do was

killall gpg-agent

@bm-synth
Copy link

I you're on WSL2, maybe this can help:

* Add those lines to `~/.gnupg/gpg.conf`

use-agent
pinentry-mode loopback


* Add this line to `~/.gnupg/gpg-agent.conf`

allow-loopback-pinentry

Thanks, worked on WSL2.

Thank you @luiguip , that was the fix for me!

@Muneer94
Copy link

Even after trying the above methods if the problem didn't get resolved, you can restart gpg-agent

systemctl --user status gpg-agent
systemctl --user restart gpg-agent

@naezith
Copy link

naezith commented Dec 5, 2023

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

This is the true solution 👍

@theBeardA
Copy link

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

this works like a charm 🚀

@Pablo-pixtm-365
Copy link

Pablo-pixtm-365 commented Dec 13, 2023

I tried differents solutions:

1.- Change the path in "git config --global gpg.program"
2.- See if there were any misspelled variables
3.- echo "test" | gpg --clearsign

But they didn't work.

Finally the solution was run:

git config --global gpg.program gpg

if you use gpg2, change gpg for gpg2

I hope this solution works for you

@scotteg
Copy link

scotteg commented Dec 25, 2023

After upgrading my OSX to Monterey it stoped to work without reason. The GIT_TRACE didn't help to much because everything was correctly set. In the end I reinstalled the GPG Sutie via brew with the command brew reinstall --cask gpg-suite and it fixed the issue.

Doing this resolved my issue. Thanks!

@JorgeNachtigall
Copy link

I you're on WSL2, maybe this can help:

  • Add those lines to ~/.gnupg/gpg.conf
    use-agent 
    pinentry-mode loopback
    
  • Add this line to ~/.gnupg/gpg-agent.conf
    allow-loopback-pinentry
    

GOAT, it worked

@EfrainOlivaresEv
Copy link

🙏
Saved me lots more time after spending a bunch of time debugging ...

@EvieePy
Copy link

EvieePy commented Jan 3, 2024

After spending hours debugging this, the problem was that I was using single quotes for this command, E.g:
git config --global gpg.program 'C:\Program Files (x86)\GnuPG\bin\gpg.exe'

Instead of double quotes, like so:
git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

Thanks for the help though!

@SelinaRaynor
Copy link

Thanks for helping me out :)

@syedamanat
Copy link

syedamanat commented Jan 10, 2024

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Thanks for this!

10th-Jan-2024; Still works (mac m1)

@Jphn
Copy link

Jphn commented Jan 11, 2024

Thanks man, it worked for me!

@adriguerra
Copy link

My issue was that I had added the PGP key with my email, while my commits on the repo were signed with my GitHub-provided noreply email address.

To solve this issue, I had to run gpg --edit-key [your key] followed by gpg> adduid to add the second email address.

https://docs.github.com/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key

@HimangshuDe
Copy link

HimangshuDe commented Feb 17, 2024

Hello Devs,
Since I am a newcomer to git and GitHub. I have also faced the same problem. Let me state that in detail below.

Problems I have faced:

  1. I have installed git and have generated ssh-key from there and added it to my GitHub account. It worked.

  2. I have installed GPG program for adding GPG key into my account and added to git thereafter. I did all the necessary steps. Added that into my account. Worked fine.

  3. Now whenever I commit any changes, I get that error.

Solution: [Worked in my case]

Since I am on Windows system. I did the following steps that resolved my problem.

  1. Run "Windows Powershell" in admin mode.

  2. Then I set the Execution Policy to AllSigned through this command Set-ExecutionPolicy AllSigned. After that press A and hit Enter.
    Screenshot 2024-02-17 220040

  3. Then I regenerated the GPG key and added that to git and also in my GitHub account.

  4. I went ahead and did the commit, it worked fine!
    Screenshot 2024-02-17 215713

My System Details:

  1. Windows 10 Pro v22H2 [Activated]
  2. Intel i5-3570K CPU Quad Core (Ivy Bridge codename)
  3. 8GB installed DDR3 RAM

Hope you may find this useful!

Regards!
Happy Coding

@usoro007
Copy link

@NirajanMahara
You saved the day and allowed me to get some rest! Thank you!

@danielfromCL
Copy link

Thanks for the help, worked for me! 🙌

@BakiVernes
Copy link

GOAT 🐐

@Impa10r
Copy link

Impa10r commented Mar 24, 2024

gpg --status-fd=2 -bsau F93581548CDBCCB7
[GNUPG:] KEY_CONSIDERED E4C9A7533D31D43B288E162FF93581548CDBCCB7 2
[GNUPG:] BEGIN_SIGNING H10

and it just hangs there.

Hello, did you find the solution? It obviously waits for the password. I am on Ubuntu and I had the same problem when creating the key, used some tricks from here. But now am stuck when trying to use the key for the first time. Can't believe this is so hard to do.

@hu-qi
Copy link

hu-qi commented Mar 24, 2024

I tried differents solutions:我尝试了不同的解决方案:

1.- Change the path in "git config --global gpg.program"1.- 更改“git config --global gpg.program”中的路径 2.- See if there were any misspelled variables 2.- 查看是否有任何拼写错误的变量 3.- echo "test" | gpg --clearsign 3.- 回显“测试” | gpg--clearsign

But they didn't work.但他们没有工作。

Finally the solution was run:最后运行解决方案:

git config --global gpg.program gpg

if you use gpg2, change gpg for gpg2如果您使用gpg2,请将gpg更改为gpg2

I hope this solution works for you我希望这个解决方案适合您

Thanks, It worked for me!

@zrajeev
Copy link

zrajeev commented Mar 25, 2024

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

This is the true solution 👍

@bdangeb6tp
Copy link

bdangeb6tp commented Mar 27, 2024

What worked for me was slightly different than brew install pinentry-mac

I instead used reinstall since it was already installed.

brew reinstall pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

@JordanUnderwood12
Copy link

I was also having a similar problem, but now everything is good.

@Fuseteam
Copy link

Fuseteam commented Apr 10, 2024

gpg --status-fd=2 -bsau F93581548CDBCCB7
[GNUPG:] KEY_CONSIDERED E4C9A7533D31D43B288E162FF93581548CDBCCB7 2
[GNUPG:] BEGIN_SIGNING H10

and it just hangs there.

Hello, did you find the solution? It obviously waits for the password. I am on Ubuntu and I had the same problem when creating the key, used some tricks from here. But now am stuck when trying to use the key for the first time. Can't believe this is so hard to do.

i also ran into this, i managed to workaround it using this @NirajanMahara steps at https://gist.github.com/paolocarrasco/18ca8fe6e63490ae1be23e84a7039374?permalink_comment_id=3767413#gistcomment-3767413; by doing that it prompts for the password, after which it just works. i suppose there should be a way to configure gpg to prompt for a password properly

@saadazghour
Copy link

saadazghour commented Apr 10, 2024

I'm on Ubuntu, Thanks @NirajanMahara ,It's worked for me 👍

@MuhanguziDavid
Copy link

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

Thank you!

@robrakaric
Copy link

My issue was that I had added the PGP key with my email, while my commits on the repo were signed with my GitHub-provided noreply email address.

To solve this issue, I had to run gpg --edit-key [your key] followed by gpg> adduid to add the second email address.

https://docs.github.com/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key

This worked for me! Thanks

@bitsector
Copy link

On MacOS, I have to install pinentry-mac to enter passphrase

brew install pinentry-mac
echo "pinentry-program $(which pinentry-mac)" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

This is the true solution 👍

This worked for me as well. Thanks @bdangeb6tp !!

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