返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
Windows

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.

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

相关文章

讨论

共 0 条

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

加载评论中…