gpg: can't connect to the agent: IPC connect call failed
Asked Answered
V

14

104

I am having a problem while trying to decrypt some keys using GPG. The following output is given to me:

gpg: can't connect to the agent: IPC connect call failed

I already edited some files, pointed in this tutorial: https://michaelheap.com/gpg-cant-connect-to-the-agent-ipc-connect-call-failed/ but with no success.

Possible reasons for that?

Varro answered 10/10, 2017 at 18:39 Comment(1)
People experiencing this should try this first: gpgconf --kill gpg-agentDocile
K
195

Even I had the above issue in Ubuntu 20 WSL, I tried all the below | above suggestions, but none worked for me.

root@7400-9888K13:/mnt/c/Users/PKammari# wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
gpg: can't connect to the agent: IPC connect call failed

What did I do to resolve the issue?

  • remove gpg
  • install other version of gpg.

How do I do it?
apt remove gpg ( follow the instructions)
apt install gnupg1 (follow the instructions)

Option 2. sudo apt update --y

`sudo apt remove gpg`

`sudo apt-get update -y`

`sudo apt-get install -y gnupg1` 

Proof. (refer to the screenshot):
enter image description here

Kyser answered 9/5, 2020 at 6:45 Comment(13)
WSL2 Ubuntu-20.04. This help me fix the issueBodgie
WSL1 Ubuntu-20.04. This fixed the issue for me as well (trying to install Sublime).Ginn
Worked for me on WSL2 Ubuntu-20.04 (trying to install docker)Pecten
On WSL1 Ubuntu, this worked for me. thank you. Trying to install yarnPamphlet
Doesn't work for me on WSL2 Ubuntu-20.04 --- keep getting error: gpg failed to sign the data fatal: failed to write commit object I do have a keySubacid
this removes also software-properties-common and you need to install it back for add-apt-repositoryDanieldaniela
Didn't do anything for me, I'm afraid. I still get the IPC connect call failed error. :/Sticker
WSL2 Windows 10 ProN this solution worked for me, just uninstalled and installed, then ran sudo apt update --yImprovise
WSL here and also fixed the issue for meCatha
I suspect in most cases it's not needed anymore to remove gpg before installing gnupg1. Apparently, they can coexist and this problem is solved anyways. I had the same issue as @AlexPunnen, and reinstalling software-properties-common brought back gpg as well. However, the issue disappeared, so apparently the two packages can coexist and the right one is used when adding keys :)Incline
Worked for me when installing MongoDB on WSL 1 Ubuntu-20.04Brubaker
@Incline your suggestion didn't work on WSL2 Ubuntu 20.04. I had to remove gpg to get it to work. I was trying to add docker's gpg key while installing docker.Valeta
@Valeta that's weird. So maybe what does the trick is uninstalling it and THEN reinstalling it together with software-properties-common and gnupg1... I'm sorry for thatIncline
R
45

In my case the agent wasn't even started. This is what I did to resolve:

C:\Program Files (x86)\gnupg\bin>gpg-connect-agent -v
gpg-connect-agent: no running gpg-agent - starting 'C:\Program Files (x86)\gnupg\bin\gpg-agent.exe'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: connection to agent established
> ^Z

Afterwards the commands to the agent started working.

Reine answered 18/11, 2019 at 15:7 Comment(5)
For me, even that doesn't work: gpg-connect-agent: can't connect to the agent: IPC connect call failedPeripteral
Run it in an elevated CMD/Powershell consoleFlavoprotein
I had been using the --homedir parameter, and that screws with gpg-agent. If you're doing that, then instead try setting the environmental variable GNUPGHOME to your homedir.Testes
Another method without having to force exit out: gpgconf --launch gpg-agentGrassi
I have gpg being invoked by Maven. I think the reason gpg stopped working for me was the act of upgrading from Windows 10 to 11 (which I did earlier today). This solution worked great (thx Will Buffington), when using cmd.exe with the Administrator privileges (thx @Otto).Bagehot
A
31

There is probably already a gpg-agent running on the system, which your gpg command is unable to connect to.

If you do a pkill -9 gpg-agent and then source <(gpg-agent --daemon) to restart the agent, you should be able to connect to the pinentry-curses for inputting your password.

Abbotsun answered 1/11, 2017 at 13:47 Comment(3)
I did only the kill part, the daemon restarted automatically in Debian 9.Himes
I had killed the agent and expected it to restart upon login which it didn't for me. The source<(gpg-agent --daemon) syntax is new to me. This appears to start the agent with its parent PID set to 1.Morie
Easiest way: gpgconf --kill gpg-agentDocile
I
15

To hopefully add to preetam's excellent answer above for those very new to this.

To install gnupg1 - if you get the error "Package gnupg1 is not available, but referenced....."

sudo apt remove gpg
sudo apt-get update -y
sudo apt-get install -y gnupg1 
Intersidereal answered 22/5, 2020 at 8:2 Comment(0)
S
11

Mine is a windows machine, and when I do git commit I get the following message. I have already configured gpg keys on my machine.

gpg: can't connect to the gpg-agent: IPC connect call failed
gpg: keydb_search failed: No agent running
gpg: skipped "BBB42EB62E25E8EB33AE2E65F40A504840B1C66B": No agent running
gpg: signing failed: No agent running
error: gpg failed to sign the data
fatal: failed to write commit object

Will Buffington answer worked for me.

I had to apply the command

gpg-connect-agent -v

repeatedly as shown below. And it worked in the third attempt.

gpg connect agent command

Once the I get the message connection to agent established, I now ran the commit command again. Now its successful. Note the -S flag to sign my commits.

git commit successful

Update

This morning, it did not start even after 3 attempts. I had to double click the exe from its installed location.

double click gpg agent to start

Scilicet answered 14/8, 2022 at 3:49 Comment(2)
Worked at second attempt. Glad to find your answer.Septimal
The update worked for me (double-click on gpg-agent.exe)Gorgeous
D
6
apt-get install -y gnupg gnupg1
cp -a /usr/bin/gpg /usr/bin/gpg2
ln -sf /usr/bin/gpg1 /usr/bin/gpg

apt-key worked for me after executing those commands.

I'm WSL 2.0 with Ubuntu 20.04 (Windows 10 Build 2004).

Reason:

uninstalling gnupg (2.x) also uninstalls gpg-agent, which is required.

installing gnupg1 (1.x) will install only gpg binary, not gpg-agent.

Both are required to work, but we want gnupg1 (1.x) to be the default "gpg" command (despite working with 2.x support-tools).

Degraw answered 15/8, 2020 at 23:11 Comment(1)
This is actually the solution for me on Ubuntu 18.04, thanks!Equerry
S
5

For me, previous responses worked, but partially, what made the magic in my case was a combination of all, see the commands below.

If you get error add-apt-repository: command not found, then, install package software properties common.

sudo apt remove gpg
sudo apt-get update -y
sudo apt-get install -y gnupg1

# In case of Error when adding "ppa" with message: add-apt-repository: command not found
sudo apt-get install software-properties-common

# Now, the hack
sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
wget https://launchpad.net/~rafaeldtinoco/+archive/ubuntu/lp1871129/+files/libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb
sudo dpkg --install libc6_2.31-0ubuntu8+lp1871129~1_amd64.deb
sudo apt-mark hold libc6 #to avoid further update

# Edit: /var/lib/dpkg/info/libc6:amd64.postinst and remove the sleep 1 that is in nearly the last line.
Spleen answered 16/6, 2020 at 16:33 Comment(4)
I tried that, but now it acts like NodeJS it's installed, but I don't know where (it's not in /usr/bin): sudo apt install nodejs ... .nodejs is already the newest version (12.18.3-deb-1nodesource1). ... nodejs -v Command 'nodejs' not found, but can be installed with: sudo apt install nodejsPeripteral
@StanislavDušek, In my case, I installed in Ubuntu with: sudo apt-get install nodejs Then, simply run: node -v (whitout 'js') $ node -v >> output: v14.8.0 Did you tried that?Spleen
The issue with libc6 nanosleep is fixed in the next windows update.Benedikta
@AdrianEscutiaSoto I needed it to install new NodeJS on Ubuntu and in the end, I used different solution - gist.github.com/noygal/6b7b1796a92d70e24e35f94b53722219 - in a nutshell by installing node with latest nvm :)Peripteral
B
3

Based upon other behaviors in my Windows 10 system and through experimentation, I believe sometimes Windows Defender blocks gpg-agent from running because of a Windows Defender bug that slows the system trying to access low-level CPU counters.

Read Windows Defender can Significantly Impact Intel CPU Performance, We have the Fix. Work around the issue by downloading Counter Control from TECHPOWERUP and clicking "Reset Counters" when this problem arises. (See below.)

In my case I would frequently get the following error while trying to sign JAR files for deployment to Maven Central.

gpg: can't connect to the gpg-agent: IPC connect call failed
gpg: keydb_search failed: No agent running
gpg: skipped "…": No agent running
gpg: signing failed: No agent running

Sometimes if I kept trying over and over and over, eventually it would succeed.

Based on other answers, when this happened I trying manually connecting to the gpg-agent, but even that would time out:

> gpg-connect-agent --verbose
gpg-connect-agent: no running gpg-agent - starting 'C:\\Program Files (x86)\\GnuPG\\bin\\gpg-agent.exe'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: waiting for the agent to come up ... (4s)
gpg-connect-agent: waiting for the agent to come up ... (3s)
gpg-connect-agent: waiting for the agent to come up ... (2s)
gpg-connect-agent: waiting for the agent to come up ... (1s)
gpg-connect-agent: can't connect to the gpg-agent: IPC connect call failed
gpg-connect-agent: error sending standard options: No agent running

Because I've been experiencing similar slowdown issues on my machine seemingly related to Windows Defender, I ran "Counter Control" and sure enough, it showed that Windows Defender was maxing out the counter access as described in the article above. (Image embedded from the article.)

Counter Control showing Defender

I tried to manually connect to gpg-agent again, but this time I hit "Reset Counters" in the utility just as gpg-connect-agent was retrying. When I did this, it immediately connected!

> gpg-connect-agent --verbose
gpg-connect-agent: no running gpg-agent - starting 'C:\\Program Files (x86)\\GnuPG\\bin\\gpg-agent.exe'
gpg-connect-agent: waiting for the agent to come up ... (5s)
gpg-connect-agent: connection to the agent established

This seems unlikely to be a coincidence that it would connect at just the moment I reset the counters. Moreover Windows Defender has been causing other slowdown problems on my machine.

I believe that buggy behavior of Windows Defender is causing this problem on my machine. Please investigate and report if you can reproduce this workaround. (Note that, as per the article, this problem only affects certain generations of Intel CPUs.)

Update: Upon further testing, I'm still getting can't connect to the gpg-agent even if I've already reset counters to prevent Windows Defender from hogging the CPU as explained above. For some reason I normally still have to manually run gpg-connect-agent. Now it may be that resetting the counters while gpg-agent was trying to connect allowed it to connect. And it could still be be that Windows Defender is stopping gpg-agent from connecting when my system starts up. But at this moment all I know is that 1) gpg-agent isn't starting up automatically, 2) I have to run gpg-connect-agent manually, and 3) even running gpg-connect-agent will time out unless I reset the CPU counters to stop Windows Defender from hogging the CPU.

Bordure answered 3/10, 2022 at 14:49 Comment(0)
K
0

I had the same problem. In my case, the gpg config files were somehow corrupted. To solve it, I have removed all the configurations inside ~/.gnupg (make sure to backup any keys that you still need). Then I have reinstalled gpg and everything worked well.

Kentkenta answered 22/5, 2019 at 15:47 Comment(0)
T
0

On WSL1 Ubuntu 20.04 following workaround available: https://github.com/microsoft/WSL/issues/5125#issuecomment-619097534

sudo add-apt-repository ppa:rafaeldtinoco/lp1871129
sudo apt update
sudo apt install libc6=2.31-0ubuntu8+lp1871129~1 -y
sudo apt-mark hold libc6
Tramp answered 21/5, 2020 at 20:3 Comment(0)
W
0

I had to use:

sudo apt autoremove gpg gnupg1 gnupg2
Wynellwynn answered 1/6, 2020 at 11:54 Comment(0)
M
0

In windows subsystem Ubuntu 20 works these steps:

  1. sudo apt remove gpg
  2. sudo apt-get update -y
  3. sudo apt-get install -y gnupg1

After that steps appear "Ok"

enter image description here

Mccown answered 19/10, 2020 at 17:16 Comment(0)
B
0

I had the same problem when I killed the agent. It was not able to connect to agent again. So I had to remove all gpg gpg-related packages, and reinstall. I had to remove gpg-agent as well. so what I did

sudo apt remove gpg gpg-agent
sudo apt-get install -y gpg 
Barret answered 12/3, 2021 at 19:7 Comment(0)
G
0

I was able to connect without installing new software. In my case the issue was that the IPC file wasn't in the expected position.

Check if gpg-agent with ps -eaf | grep gpg is running and kill it if it is running with killall gpg-agent

Start gpg-agent with verbose

$ gpg-agent --daemon -v
...
GPG_AGENT_INFO=/tmp/.../S.gpg-agent; export GPG_AGENT_INFO

copy-paste the GPG_AGENT_INFO line, including the export, in the shell where you need the agent.

Gladiolus answered 6/5, 2022 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.