Git in Powershell saying 'Could not find ssh-agent'

GitSsh

Git Problem Overview


I have git installed and it works great in the command prompt, but when I open up powershell it gives me this warning:

WARNING: Could not find ssh-agent

I have pageant running and loaded with my private key. This works in all the gui tools and the command prompt but not in Powershell.

What's going on?

Git Solutions


Solution 1 - Git

For those looking for a detailed explanation have a read of this blog post. Below is a quote from the blog post. Ultimately the ssh-agent.exe needs to be in the path, or resolved some other way.

EDIT: It appears most of the people don't bother reading the linked blog and the original extract did not quote the full solution, so I've expanded the quote from the blog below.

There are numerous ways to resolve the error, based on the likes to all other answers. One known to work is quoted below. Scan though other answers they may be more appropriate for you.

> When I restarted my PowerShell prompt, it told me it could not start SSH Agent. > > It turns out that it was not able to find the “ssh-agent.exe” executable. That file is located in C:\Program Files (x86)\Git\bin. but that folder isn’t automatically added to your PATH by msysgit. > > If you don’t want to add this path to your system PATH, you can update your PowerShell profile script so it only applies to your PowerShell session. Here’s the change I made. > > $env:path += ";" + (Get-Item "Env:ProgramFiles(x86)").Value + "\Git\bin" > > On my machine that script is at: > C:\Users\Haacked\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1

Solution 2 - Git

You can add two lines to the top of your profile (type ise $profile) to fix this PoshGit issue without polluting your Path. Then run . $profile to reload your profile.

For 32-bit git
Set-Alias ssh-agent "${env:ProgramFiles(x86)}\git\bin\ssh-agent.exe"
Set-Alias ssh-add "${env:ProgramFiles(x86)}\git\bin\ssh-add.exe"
For 64-bit git
Set-Alias ssh-agent "$env:ProgramFiles\git\usr\bin\ssh-agent.exe"
Set-Alias ssh-add "$env:ProgramFiles\git\usr\bin\ssh-add.exe"

Solution 3 - Git

I figured it out. You need to set GIT_SSH environment variable on your machine to point to plink.exe. This could be the one installed with TortoiseHg / TortoiseGit / Git Extensions or you can download it from Putty Download Page, but just make sure that you use the same one system wide. Best to log out from your Windows session to make sure this variable gets set for all Explorer instances and command windows.

Solution 4 - Git

If you are using posh-git and getting this warning, you can turn it off by commenting (adding a '#' sign to) the following line

Start-SshAgent -Quiet

In the file

Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1

Solution 5 - Git

To run ssh-agent with specified key I wrote this code:

$gitexepath = cmd /c where git
$gitbindir = Join-Path $gitexepath "..\..\bin"
$sshagentpath = Join-Path $gitbindir "ssh-agent.exe"
$sshaddpath = Join-Path $gitbindir "ssh-add.exe"
$keypath = "...key path...":
$sshagentres = cmd /c $sshagentpath 
$env:SSH_AUTH_SOCK = [System.Text.RegularExpressions.Regex]::Match($sshagentres, "(?<=SSH_AUTH_SOCK=).+?(?=;)").Value
$env:SSH_AGENT_PID = [System.Text.RegularExpressions.Regex]::Match($sshagentres, "(?<=SSH_AGENT_PID=).+?(?=;)").Value
cmd /c $sshaddpath $keypath

Solution 6 - Git

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKhalid AbuhakmehView Question on Stackoverflow
Solution 1 - GitTaras AleninView Answer on Stackoverflow
Solution 2 - GitbrianaryView Answer on Stackoverflow
Solution 3 - GitKhalid AbuhakmehView Answer on Stackoverflow
Solution 4 - GitAhmedView Answer on Stackoverflow
Solution 5 - GitStanislav BerkovView Answer on Stackoverflow
Solution 6 - GitTrueWillView Answer on Stackoverflow