9

I like to sign my git commits with my PGP key, so I was quite alarmed when I went to git commit -S but instead of prompting for my PGP key passphrase, git just started hanging. I haven't made a change to my GPG setup in several months and have made many commits since then with no problem. Additionally, when I attempt to view my private keys with gpg -K, gpg hangs. However, when I run gpg -k to view my public keys, it returns the list like normal. Hopefully someone will have some idea of what is causing this problem and how to fix it.

  • are you doing this over ssh? if so, do you have gpg-agent or similar setup in the .bashrc (etc) of the remote system, and configured to prompt on the remote's X display or similar? i've had similar problems in the past (e.g. ssh-ing from a terminal on my mythtv box to my desktop machine to run something requiring gpg. also had similar issues with ssh-agent), and i brute-force "fixed" it with export GPG_TTY=$(tty) in the .bashrc, to make sure the prompt is always on the current tty. i can't stand GUI passwd prompts anyway. – cas Jul 28 '17 at 6:07
  • 1
    No, I'm not doing it over SSH. What's weird is that I found that if I kill gpg-agent, gpg works again. I'm trying to figure out why and make a long term solution. – John Leuenhagen Jul 28 '17 at 16:10
  • I just noticed in the gpg-agent man page that setting GPG_TTY as above isn't something I hacked up to work, it's required. The man page says you should always set it in your .bashrc as I did, and also says It is important that this environment variable always reflects the output of the tty command. - that must have been where I got it from. One other thing you need to be careful of is the pinentry program used by gpg-agent. I have mine set (in ~/.gnupg/gpg-agent.conf) to /usr/bin/pinentry-curses – cas Jul 28 '17 at 16:40
9

I came across this exact issue (OSX Sierra 10.12.6, gpg/GnuPG 2.2.5)

Commands that would hang:

gpg -K # --list-secret-keys
gpg -d # --decrypt
gpg --edit-key
gpgconf --kill gpg-agent

My solution was the same as mentioned by John above (ie. kill gpg-agent) as most other methods on how-can-i-restart-gpg-agent would also hang.

# Solution    
pkill -9 gpg-agent

Then for signing git commits I set the tty env as mentioned by cas above and also at gpg-failed-to-sign-commit-object.

export GPG_TTY=$(tty)
  • So do you have to re-kill gpg every time you reboot? That's what I've been having to do for a long time now. I hope we'll find a way to fix it for good. – John Leuenhagen Mar 22 '18 at 2:33
  • Just started having the issue myself. Killing the gpg-agent seems to be the only way to get it working again. – Alexis Tyler May 29 '18 at 4:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.