返回文章列表文章索引阅读全文
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 许可协议。转载请注明出处!

相关文章

讨论

共 0 条

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

加载评论中…