From SSH Remote to Git Push: Implementing Passwordless Login on Windows in One Go
I've always hoped to achieve passwordless remote connection via SSH keys on Windows, just like on Linux systems. Manually entering passwords every time I remotely connect to a server is both inconvenient and less secure, especially when I need to operate frequently.
目录7 个章节
Preface
I've always wished that on Windows, I could achieve passwordless remote connections via SSH keys, just like on Linux. Manually entering passwords each time I connect to a server remotely is both tedious and insecure, especially when I need to operate frequently.
The issue of SSH login has been resolved in a previous article: Implementing Passwordless SSH Login on Windows 10
Windows SSH Support
A Recap
Windows includes a built-in service called OpenSSH Authentication Agent. This service manages SSH keys, which means I don't need to install any additional third-party tools to easily set up SSH passwordless login.
Following online tutorials, I simply enabled the OpenSSH Authentication Agent service, configured my SSH keys, and could then SSH into the server without a password.
Git Push Issues
However, when I tried to perform a git push operation via Git, I was still prompted to enter a password.
I had already configured SSH keys, so why was Git still asking for a password when performing operations?
Clearly, just starting the OpenSSH service didn't solve the problem. Therefore, I decided to analyze the cause of this issue in depth to see if there was anything else that needed adjustment.
Testing with Git Bash
To further troubleshoot the issue, I decided to test it in Git Bash.
Git Bash is a tool used to execute Git commands, so I ran the ssh-add -l command in Git Bash to verify whether my SSH key was loaded correctly. It turned out that the ssh-agent in Git Bash wasn't even running!
That's when I suddenly realized that Git Bash and the SSH tool built into Windows don't seem to be fully compatible — Git doesn't use Windows' SSH tool by default.
Git Uses Its Own SSH Tool
Next, I further explored this issue.
I learned that Git actually has its own SSH tool and does not default to using the OpenSSH tool included with the Windows system.
The tool that comes with Git and the one included with Windows are different. Therefore, even if the OpenSSH Authentication Agent service is configured in Windows, Git will not automatically use it.
Configure Git to Use Windows Default SSH Tool
Since Git does not use Windows' built-in SSH tool, you need to configure it manually. I told Git to use Windows' default SSH tool by executing the following command:
git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
This command tells Git to use the ssh.exe found in the Windows system to handle SSH connections during operations, instead of using the tool bundled with Git. After completing the configuration, I tried the git push operation again.
All Done
This time, when I ran git push, everything went smoothly, and it didn't prompt me for a password again. By doing this, I successfully integrated Git operations with Windows' SSH configuration, achieving password-free login. Now, whether it's connecting to a remote server via SSH or using Git for version control, I no longer need to enter a password every time.
_EOF_
From SSH Remote to Git Push: Implementing Passwordless Login on Windows in One Go
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
2024年,提升Windows开发和使用体验的一些实践 - 包管理器篇
Windows包管理器?scoop开源自定义,winget官方凑合,WingetUI图形界面总算不用手动折腾了。效率提升?哼,总算不是Linux小众玩家的专利。
2024-02-29 · Windows · 约 1 分钟
在 Windows 11 上使用 Hyper-V 虚拟机
WSL开了Hyper-V,VMware直接报废,嵌套虚拟化?做梦。改用原生Hyper-V管理器,开启倒简单。Windows Admin Center登录失败,懒得折腾,直接用控制台。
2026-03-10 · Windows · 约 1 分钟
修复winget命令找不到的问题
微软官方包管理器winget在Windows 10 1809以上版本中,用于快速安装、更新和管理应用程序。本文介绍了因系统环境变化导致winget命令失效的问题,分析了可能原因,并提供了解决方案及预防措施,包括修复命令、定期更新检查、备份环境变量等。
2025-04-04 · Windows · 约 1 分钟
Windows的Linux子系统上配置SSH服务器
安装openssh 这个不用啰嗦太多,首先需要安装openssh-server和openssh-client。 修改sshd-config配置 需要关注的就是这三行。 UsePrivilegeSeparation no #因为wsl没有实现chroot PasswordAuthentication yes ListenAddress 0.0.0.0
2021-12-18 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…