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.
2 Answers
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. Mar 22, 2018 at 2:33
-
Just started having the issue myself. Killing the
gpg-agent
seems to be the only way to get it working again. May 29, 2018 at 4:48 -
1Got this issue on Ubuntu 22.04, and it persists even after killing
gpg-agent
. Dec 4, 2022 at 3:13 -
-
When I kill
gpg-agent
in a Visual Studio Code devcontainer, it comes right back. Aug 16 at 20:18
$ ps aux | grep -E "gpg-agent"
alper 28970 0.0 92436 3284 15:31 0:00 /usr/bin/gpg-agent --supervised
Here output variable contains 28970
.
from subprocess import Popen, PIPE
import signal
def kill_process_by_name(process_name):
p1 = Popen(["ps", "auxww"], stdout=PIPE)
p2 = Popen(["grep", "-E", process_name], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # noqa
p3 = Popen(["awk", "{print $2}"], stdin=p2.stdout, stdout=PIPE)
p2.stdout.close()
output = p3.communicate()[0].decode("utf-8").strip()
lines = output.splitlines() # awk may return more than one pid number
for pid in lines:
if pid.isnumeric():
os.kill(int(pid), signal.SIGKILL)
-
This isn't really a solution to the problem, just a workaround. I'd advise against auto-killing processes in a script like this. Mar 9, 2022 at 18:05
-
Why are you against auto-killing processes in a script like this? Wouldn't you kill processes in a bash-script using
kill -9 $(ps auxww | grep -E "[p]rocess_name" | awk '{print $2}') > /dev/null 2>&1
?– alperMar 9, 2022 at 18:50 -
that would be just as bad. My point is that automatically killing a process to get it to work isn't a solution. It's just an ugly workaround, and I wouldn't feel comfortable using it. Mar 10, 2022 at 19:42
-
What would you fell comfortable to use? Don't you ever automatically kill a process and restart it in your on computer, or ever restart the operating system if somehing unexpected happens?– alperMar 10, 2022 at 22:12
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 withssh-agent
), and i brute-force "fixed" it withexport 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.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 saysIt 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