Powershell 中的 Git 说“找不到 ssh-agent”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7470385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git in Powershell saying 'Could not find ssh-agent'
提问by Khalid Abuhakmeh
I have git installed and it works great in the command prompt, but when I open up powershell it gives me this warning:
我已经安装了 git 并且它在命令提示符下运行良好,但是当我打开 powershell 时,它给了我这个警告:
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.
我正在运行选美比赛并加载了我的私钥。这适用于所有 gui 工具和命令提示符,但不适用于 Powershell。
What's going on?
这是怎么回事?
回答by Taras Alenin
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.
对于那些寻求详细解释的人,请阅读这篇博客文章。以下是博文中的引述。最终ssh-agent.exe
需要在路径中,或者以其他方式解决。
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
当我重新启动 PowerShell 提示符时,它告诉我它无法启动 SSH 代理。
事实证明,它无法找到“ssh-agent.exe”可执行文件。该文件位于 C:\Program Files (x86)\Git\bin。但该文件夹不会被 msysgit 自动添加到您的 PATH 中。
如果您不想将此路径添加到您的系统 PATH,您可以更新您的 PowerShell 配置文件脚本,使其仅适用于您的 PowerShell 会话。这是我所做的更改。
$env:path += ";" + (Get-Item "Env:ProgramFiles(x86)").Value + "\Git\bin"
在我的机器上,该脚本位于:C:\Users\Haacked\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1
回答by brianary
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.
您可以在您的个人资料(类型ise $profile
)的顶部添加两行来解决这个 PoshGit 问题,而不会污染您的路径。然后运行. $profile
以重新加载您的配置文件。
For 32-bit git
对于 32 位 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
对于 64 位 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"
回答by Khalid Abuhakmeh
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 Extensionsor 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.
我想到了。您需要GIT_SSH
在您的机器上设置环境变量以指向plink.exe
. 这可能是与 TortoiseHg / TortoiseGit / Git Extensions一起安装的那个,或者您可以从Putty 下载页面下载它,但只需确保您在系统范围内使用相同的一个。最好从 Windows 会话中注销,以确保为所有资源管理器实例和命令窗口设置此变量。
回答by Ahmed
If you are using posh-git and getting this warning, you can turn it off by commenting (adding a '#' sign to) the following line
如果您正在使用 posh-git 并收到此警告,则可以通过注释(添加“#”符号)以下行来关闭它
Start-SshAgent -Quiet
In the file
在文件中
Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1
回答by Stanislav Berkov
To run ssh-agent with specified key I wrote this code:
要使用指定的密钥运行 ssh-agent,我编写了以下代码:
$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
回答by TrueWill
This has been fixed; see https://github.com/dahlbyk/posh-git/issues/160
这已被修复;见https://github.com/dahlbyk/posh-git/issues/160
You can update posh-git.
您可以更新 posh-git。