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 许可协议。转载请注明出处!
相关文章
Windows10-快捷键大全,整理+排版
前言 偶然在微软官网看到的,整理了一下,非常全面。不只有Windows10能用,大部分快捷键在7/8/8.1里都是通用的。 发现这东西对提高效率帮助很大啊,下面是整理之后的。 复制、粘贴及其他常规的键盘快捷方式 | 按键 | 操作
2021-12-18 · Windows · 约 1 分钟
在 Windows 11 上使用 Hyper-V 虚拟机
WSL开了Hyper-V,VMware直接报废,嵌套虚拟化?做梦。改用原生Hyper-V管理器,开启倒简单。Windows Admin Center登录失败,懒得折腾,直接用控制台。
2026-03-10 · Windows · 约 1 分钟
忘记WSL的root密码怎么办
解决方法 首先,打开WSL是不需要输入密码的,如果你打开WSL时的默认用户不是root,请按照一下方式修改。 修改默认登录WSL用户 以管理员权限启动Powershell lxrun /setdefaultuser root 此时重新打开WSL就是root用户了,并且不需要密码。 然后输入以下命令修改密码。 passwd root About 了解更多有趣的操作请关注我的微信公众号:DealiA
2021-12-18 · Windows · 约 1 分钟
使用twinkle-tray快捷调整多个显示器的亮度
自从安装了这个小工具,我再也没用过笔记本键盘上的快捷键了~
2025-01-26 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…