Location>code7788 >text

Remote from SSH to Git Push: Implement password-free login in one step in Windows

Popularity:775 ℃/2025-02-10 16:22:55

Preface

I have always hoped to achieve password-free remote connection on Windows like in Linux systems, like in Linux. It's both cumbersome and not too secure to enter your password manually every time you connect to the server remotely, especially if I need to do it frequently.

The SSH login problem has been solved in previous articles:Implement password-free SSH login on Windows 10

SSH support for Windows

Let's review it

Windows comes with a name calledOpenSSH Authentication AgentThe service, this service is able to manage SSH keys, which means I can easily set up SSH password-free login without additional installation of any third-party tools.

Following the online tutorial, I simply startedOpenSSH Authentication AgentService, after setting up the SSH key, you can ssh and connect to the server without password.

Git Push has problems

However, when I try to do it via Gitgit pushDuring operation, you are still asked to enter your password.

Even though the SSH key has been configured, why do you still require a password to be entered during Git operation?

Obviously, just starting OpenSSH service didn't solve the problem. So, I decided to analyze the reasons for this problem in depth to see if there is any place to adjust.

Testing with Git Bash

In order to further investigate the problem, I decided toGit BashTest it out.

Git Bash is a tool used to execute Git commands, so I ran it in Git Bashssh-add -lCommand, want to confirm whether my SSH key is loaded correctly. It turns out that thessh-agentNot started!

At this time, I suddenly realized that Git Bash and the SSH tools that come with Windows do not seem to be completely compatible, and Git does not use Windows' SSH tools by default.

Git uses its own SSH tool

Next, I further explore this issue.

I learned that Git actually has its own SSH tool and does not use OpenSSH tools in Windows by default.

The tools that come with Git are different from those that come with Windows, so even if the OpenSSH Authentication Agent service is configured in Windows, Git will not use it automatically.

Configure Git using Windows default SSH tools

Since Git does not use the SSH tool that comes with Windows, it needs to be configured manually. I told Git to use Windows' default SSH tool by executing the following command:

git config --global  "C:/Windows/System32/OpenSSH/"

The purpose of this command is to allow Git to use the Windows system when performing operations.To handle SSH connections, instead of using Git's own tools. After the configuration is complete, I try againgit pushoperate.

Get it all done

This time, when I rungit pushWhen everything went smoothly, I was not prompted to enter my password again. In this way, I successfully combined Git operations with Windows' SSH configuration to achieve password-free login. Now, whether it's SSH connection to a remote server or using Git for version control, I no longer need to enter my password every time.