You should not use the Open SSH client that comes with Git for Windows. Instead, Windows 10 has its own implementation of Open SSH that is integrated with the system. To achieve this:
- Start the
ssh-agent
from Windows Services:
- Type
Services
in theStart Menu
orWin+R
and then typeservices.msc
to launch the Services window; - Find the
OpenSSH Authentication Agent
in the list and double click on it; - In the
OpenSSH Authentication Agent Properties
window that appears, chooseAutomatic
from theStartup type:
dropdown and clickStart
fromService status:
. Make sure it now saysService status: Running
.
- Configure Git to use the Windows 10 implementation of OpenSSH by issuing the following command in Powershell:
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
- Configure SSH to automatically add the keys to the agent on startup by editing the
config
file found at$HOME\.ssh\config
(full path -C:\Users\%YOUR_USERNAME%\.ssh\config
), and add the following lines:
Host *
AddKeysToAgent yes
IdentitiesOnly yes
You can also add the following lines if you generated an SSH key with custom name or multiple SSH keys:
Host github.com
HostName github.com
User your_user_name
IdentityFile ~/.ssh/your_file_name
- Add your SSH key to the
ssh-agent
by issuing thessh-add
command and entering your passphrase:
ssh-add $HOME/.ssh/your_file_name
- Done! Now restart your Powershell and even Windows if necessary.
If this was useful, you can buy me a coffee here. Thank you!
Yeah, I realized that what I wanted was kind of against what the title of this gist is saying. But, it's close!
I found that if the agent service startup is set to
Manual
but the agent is not running thenssh-add <key_file>
fails saying that it can't connect to the agent. If the agent is running I'm prompted for the key passphrase, and the key is added. I did find that I can remove the key from the agent anytime withssh-add -d <key_file>
, so if it's important to me that the key not be decrypted automatically every time I log into Windows, then my workaround is to delete the key manually. This way I'm able to recover the behavior I was looking for.Now, regarding the
AddKeysToAgent yes
directive in the ssh config file, for me it doesn't seem to cause keys to automatically add when the agent starts. It seems thatssh-add <key_file>
itself stores the key permanently within the agent, regardless of this directive. After adding a key, I can even delete the key file from my .ssh directory, and the agent still remembers it, even across a reboot. I did find that with the directive set, an ssh operation, for examplegit pull
, that needs a key that is not in the agent, will load that key into the agent after prompting for the passphrase. So, this directive seems to be a way to auto-add a key into the agent the first time it's needed. Again, the Windows interpretation of adding a key into the agent is to remember the key from that point forever, until you manually delete it.