1

I’m using Git Bash on Windows, and I'm trying to use the Windows OpenSSH agent to manage my SSH keys. Despite successfully starting the SSH agent as a service, I encounter the following error when trying to add my key or list loaded keys:

Error connecting to agent: No such file or directory
or
Could not open a connection to your authentication agent.

What I've Tried:

  1. Starting the SSH agent manually:
eval "$(ssh-agent -s)"  
  • The agent starts and shows a PID, but connecting to it fails.
  1. Verifying the agent is running via PowerShell:
Get-Service ssh-agent  
  • The service is running and set to automatic.
  1. Setting the SSH_AUTH_SOCK manually in Git Bash:
export SSH_AUTH_SOCK=/mnt/c/Users/chesswhiz/AppData/Local/ssh-agent.sock  
  • Still results in a "No such file or directory" error.
  1. Confirming the existence of the socket file using:
ls -l /mnt/c/Users/chesswhiz/AppData/Local/ssh-agent.sock  
  • The file does not exist or is not accessible from Git Bash.

Environment:

  • Windows 10
  • Git Bash (from Git for Windows)
  • Windows OpenSSH client and agent installed
  • The agent works properly when using PowerShell directly

Question:

How can I configure Git Bash to correctly connect to the Windows OpenSSH agent? Is there a way to make the agent socket accessible within Git Bash, or am I missing a crucial configuration step?

4
  • Have you tried to use ssh-agent.exe in git-bash bundle? Commented Apr 5 at 21:05
  • @achang2 I have edited the answer to answer your first comment Commented Apr 6 at 21:50
  • 1
    Yes, this worked, thank you! Commented Apr 6 at 21:50
  • @achang2 and I have edited the answer to address your second comment Commented Apr 6 at 21:52

1 Answer 1

2

I confirm that, using git bash, there is no /mnt:

C:\Users\vonc>where bash
C:\Users\vonc\prgs\gits\current\bin\bash.exe
C:\Users\vonc\prgs\gits\current\usr\bin\bash.exe
C:\Windows\System32\bash.exe

C:\Users\vonc>bash

vonc@voncfm MINGW64 /c/Users/vonc
$ cd /mnt
bash: cd: /mnt: No such file or directory

If you set anything in git bash, use paths starting with /c, not /mnt/c.
The Mingw-w64 upon which that bash is based on, has its cygdrive mounted on / by default (hence issues like git-for-windows/git issue 5067)


How do I tell git to use its own native ssh-agent.exe?

I always put Git folders before the Windows one:

C:\Users\vonc\home_senv\bin
C:\Users\vonc\prgs\gits\current\bin
C:\Users\vonc\prgs\gits\current\cmd
C:\Users\vonc\prgs\gits\current\usr\bin
C:\Users\vonc\prgs\gits\current\mingw64\bin
C:\Users\vonc\prgs\gits\current\mingw64\libexec\git-core
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\

That way, the ssh-agent.exe used by Git is C:\Users\vonc\prgs\gits\current\usr\bin\ssh-agent.exe.

when I try the ssh-add command it says "Could not open a connection to your authentication agent."

You can follow the GitHub guide: "Auto-launching ssh-agent on Git for Windows"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.