Using git with ssh-agent on Windows
Windows Git comes with built-in SSH? That's quite an outdated compatibility mindset. A single line of configuration can resolve this, but first, you need to manage the ssh-agent connection properly. ProxyCommand adds another layer of complexity—no wonder issues keep cropping up.
目录4 个章节
Preface
Previous articles have already solved the SSH login issue on Windows, successfully getting the Windows ssh-agent working. For details, you can refer to this article: Implementing Passwordless SSH Login on Windows 10
However, using Git still repeatedly prompts for the private key passphrase, which is quite annoying.
The reason is also simple—you can find out by opening Git Bash and running a test command:
$ ssh-add -l
Could not open a connection to your authentication agent.
It turns out that Git uses its own SSH, not the one from the Windows system. This is likely for compatibility reasons, considering Windows previously didn’t have SSH.
The solution is straightforward: simply configure Git to use Windows' SSH.
Configuration
One line of code does it all
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
Got a problem?
At first, after I finished configuring it, it kept throwing errors when I ran it.
CreateProcessW failed error:2
posix_spawnp: No such file or directory
Only after adding the -v parameter did I realize it was due to a setting in my ~/.ssh/config.
Previously, I had configured GitHub to use a proxy.
Host github.com
User git
Port 443
HostName ssh.github.com
TCPKeepAlive yes
ProxyCommand "$HOME/scoop/apps/git/current/mingw64/bin/connect.exe -S 127.0.0.1:7890 -a none %h %p"
It worked fine before when using Git's built-in SSH environment, but after switching to Windows's native SSH, it stopped working. So I commented out that ProxyCommand configuration, and everything was fine.
If anyone else encounters a similar problem, you can refer to this.
References
_EOF_
Using git with ssh-agent on Windows
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
2024年,提升Windows开发和使用体验实践 - 终端&命令行篇
哼,Windows终端重灾区?用scoop装软件,Starship美化,但WinSW自启还是垃圾。啧,又一个scoop-search替代原版,gow补齐Unix工具,gsudo模拟sudo,但proxychains有点奇怪。哦,blessed-contrib仪表盘?只是好玩罢了,不如用erdtree看目录。
2024-03-05 · Windows · 约 1 分钟
2024年,提升Windows开发和使用体验的实践经验 - RIME输入法
上一篇文章介绍了 Windows 下的包管理器,本文继续介绍输入法。 事实上 Windows 的输入法生态比 Linux/Mac 丰富很多,不过很多国产输入法存在窃取隐私、植入广告、乱安装流氓软件等问题,现在有开源的 RIME 输入法可以选择,何必受这气呢
2024-02-29 · Windows · 约 1 分钟
WSL小技巧:切换到zsh以及加入右键菜单
切换到zsh 说明 在 Windows Subsystem for Linux 中,执行 chsh -s /bin/zsh 并不能成功地将默认 shell 修改为 zsh。在打开 WSL 时,默认 shell 仍然为 bash。 这是因为WSL 在启动时并没有执行 login 相关的组件,而这些组件和默认 shell 有关。Microsoft 已经知晓了这个问题,但并没有计划去解决。 方法 我们可
2021-12-18 · Windows · 约 1 分钟
在Windows上部署OpenSSH服务
Windows终于学会了没羞没臊地用命令行装OpenSSH,结果设置界面还是卡得像屎,算了,至少比以前强点。不过这SSH连上去还是CMD,是哪个脑回路觉得这操作体验没问题啊?
2025-06-12 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…