2
votes

I'm on windows/Git bash/MingW64, trying to automate adding ssh keys for use with git. I've followed this guide, altering only the path of my private key file. It seems to work - when opening git bash I get "succeeded Identity added: /c/users/...".

ssh-add -l also shows that my key was added properly, and the port seems to be configured.

Btw - At this point $SSH_AGENT_PID matches the process in ps and $SSH_AUTH_PORT seems valid (/tmp/ssh-cEU4wbNe3vo4/agent.927 or similar)

But when I cd into my git repo and run git fetch I get:

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

After that, ssh-add no longer works, printing:

Error connecting to agent: Bad file descriptor

Which is strange because both $SSH_AUTH_PORT and $SSH_AGENT_PID Did not change at this point, and I've tried exporting them just to be sure.

Starting a new SSH-AGENT and adding my key works in the same terminal session, but trying git fetch again will have the same effect.

What is git doing that's messing with the SSH agent?

2
Given the error, it seems likely that your ssh agent has crashed. How that might happen, I don't know. - torek

2 Answers

1
votes

Finally after a long search I found it. The Windows update broke my setup šŸ˜’, specifically Openssh. I have to enter my passphrase every time since last windows update, and given that your question is fairly recent I suspect the same is true for you.

I think Win32-OpenSSH#1693 is related.

In my ~/.gitconfig in [core] there was a line (I don't remember what issue exaclty I had earlier)

   sshCommand = C:/Windows/System32/OpenSSH/ssh.exe

Removing it gave this error

error: cannot spawn C:/Windows/System32/OpenSSH/ssh3.exe: No such file or directory
error: cannot spawn C:/Windows/System32/OpenSSH/ssh3.exe: No such file or directory
fatal: unable to fork

However, replacing it with

    sshCommand = "C:/Program\\ Files/Git/usr/bin/ssh.exe"

made everything work as I expect.

I think Error connecting to agent: Bad file descriptor means something is crashing under the hood, and given that it's since recently, most likely due to the Openssl update.

P.S. You can check if your OpenSSL was updated by checking the "Date modified" of files in C:\Windows\System32\OpenSSH. For me that was very recent and aligns with the moment the ssh-agent stopped functioning.

0
votes

Try first to simplify your %PATH% before launching git bash and your SSH command.

In a new CMD, for testing:

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%

Make sure your environment variables don't have a GIT_SSH(_xxx) defined.
Type in that same CMD (before launching the bash)

set GIT

Then check if the issue persists.