曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
Windows

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.

曦远 (DealiAxy)约 6 分钟
目录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 许可协议。转载请注明出处!

相关文章

IT之家学院:让你的Win10桌面比macOS还简洁漂亮高大上

感谢IT之家网友 yiyueduzui 的原创投稿 直奔主题,先给大家看看我的电脑桌面: 有人开始骂了:你特么逗我呢?这明明就是一张图片好不啦! 我读书那么多,怎么会骗你,这真的是我的电脑桌面,不还有个桌面数字时钟呢嘛!论简洁,还有谁? 那这啥都没有,要怎么用啊? 看好啦,当我的鼠标移动到屏幕下方的时候, 出现了一个Dock栏,跟苹果系统的一样一样的。 有些图标其实是一个目录或者文件夹,当它展开的

2021-12-18 · Windows · 约 1 分钟

Win10安装Ubuntu子系统教程

一、启用“适用于Linux的Windows子系统” 通过Win10任务栏中的Cortana搜索框搜索打开“启用或关闭Windows功能”,向下滚动列表,即可看到“适用于Linux的Windows子系统”项。 勾选它,确定,然后按提示重启系统。 二、启用开发人员模式 然后进入“设置 - 更新和安全 - 针对开发人员”设置页面,选中“开发人员模式”。如图: 然后就会下载安装开发人员模式程序包,等待安装

2021-12-18 · Windows · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…