Powershell 中的 Git 提示“无法找到 ssh-agent”;

发布于 2024-12-05 16:47:52 字数 199 浏览 2 评论 0原文

我安装了 git,它在命令提示符下运行得很好,但是当我打开 powershell 时,它给了我这个警告:

WARNING: Could not find ssh-agent

我正在运行选美比赛并加载了我的私钥。这适用于所有 GUI 工具和命令提示符,但不适用于 Powershell。

这是怎么回事?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一梦等七年七年为一梦 2024-12-12 16:47:52

对于那些寻求详细解释的人,请阅读此博客发布。以下是博客文章中的引用。最终,ssh-agent.exe 需要位于路径中,或者以其他方式解析。

编辑:
看来大多数人都懒得阅读链接的博客,并且原始摘录没有引用完整的解决方案,因此我扩展了下面博客中的引用。

根据对所有其他答案的喜欢,有多种方法可以解决该错误。下面引用了一种已知有效的方法。浏览其他答案,它们可能更适合您。

当我重新启动 PowerShell 提示符时,它告诉我无法启动 SSH 代理。

事实证明,它无法找到“ssh-agent.exe”可执行文件。该文件位于 C:\Program Files (x86)\Git\bin 中。但 msysgit 不会自动将该文件夹添加到您的 PATH 中。

如果您不想将此路径添加到系统 PATH,您可以更新 PowerShell 配置文件脚本,使其仅适用于您的 PowerShell 会话。这是我所做的更改。

$env:路径+=“;” + (Get-Item "Env:ProgramFiles(x86)").Value + "\Git\bin"

在我的机器上,该脚本位于:
C:\Users\Haacked\Documents\WindowsPowerShell\Microsoft.Powershell_profile.ps1

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

傲娇萝莉攻 2024-12-12 16:47:52

您可以在个人资料顶部添加两行(输入 ise $profile)来修复此 PoshGit 问题,而不会污染您的路径。然后运行<代码>。 $profile 重新加载您的个人资料。

对于 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"

对于 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"

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"
忱杏 2024-12-12 16:47:52

如果您使用 posh-git 并收到此警告,您可以通过注释(添加“#”符号)

Start-SshAgent -Quiet

文件中的以下行来关闭它

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

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
素衣风尘叹 2024-12-12 16:47:52

我想通了。您需要在计算机上设置GIT_SSH环境变量以指向plink.exe。这可能是与 TortoiseHg / TortoiseGit / Git 扩展 一起安装的,或者您可以从 Putty 下载页面,但请确保您在系统范围内使用同一个。最好从 Windows 会话中注销,以确保为所有资源管理器实例和命令窗口设置此变量。

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.

撩心不撩汉 2024-12-12 16:47:52

为了使用指定的密钥运行 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文