Using git with powershell and ssh key with passphrase
None of these worked for me. The solution on this page did though: https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99
Here it is:
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 atC:\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.
I'm using openssh, which is shipped with Windows 10 Pro.git is installed with scoop (scoop install git
).
I had to set GIT_SSH
environment variable.
$env:GIT_SSH = (gcm ssh | select -expand source)
or for scoop users$env:GIT_SSH = (scoop which ssh)
I am using scoop
to install the git
and openssh
packages. I removed these packages and installed the package git-with-openssh
and it works now. Not entirely sure what's the difference between the packages, but I expect incompatible versions or something.