Whenever I enter a git
command in powershell, I'm asked:
Enter passphrase for key '/c/Users/***/.ssh/id_rsa'
This key is created with a passphrase:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
I've setup ssh-agent
to load on startup of my powershell, and the environment variables SSH_AUTH_SOCK
and SSH_AGENT_PID
are setup.
The connection to github is successful:
ssh -T [email protected]
replies with: Hi tkvw! You've successfully authenticated, but GitHub does not provide shell access.
This shows the git urls are used instead of https
.
git remote -v
origin [email protected]:tkvw/pshazz.git (fetch)
origin [email protected]:tkvw/pshazz.git (push)
This shows the agent is active and the key is loaded:
ssh-add -l
4096 b1:73:2a:11:....63:e8:2a:34 /c/Users/***/.ssh/id_rsa (RSA)
But calling a git operation:
git fetch
Enter passphrase for key '/c/Users/***/.ssh/id_rsa':
I have no ideas left. I don't want to use git bash
or something, I like this to work from powershell.
$ ssh-keygen -p -f ~/.ssh/id_ed25519 > Enter old passphrase: [Type old passphrase] > Key has comment '[email protected]' > Enter new passphrase (empty for no passphrase): [Type new passphrase] > Enter same passphrase again: [Repeat the new passphrase] > Your identification has been saved with the new passphrase.
Add your key to the ssh-agent Open your shell of preference (I'll use Windows Powershell in this example, applies to Powershell Core too). Add your SSH key to the ssh-agent : ssh-add (you can add the path to your key as the first argument if it differs from the default). Enter your passphrase if/when prompted to do so.
You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.
SSH uses private/public key pairs to protect your communication with the server. SSH passphrases protect your private key from being used by someone who doesn't know the passphrase. Without a passphrase, anyone who gains access to your computer has the potential to copy your private key.
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:
ssh-agent
from Windows Services:Services
in the Start Menu
or Win+R
and then type services.msc
to launch the Services window;OpenSSH Authentication Agent
in the list and double click on it;OpenSSH Authentication Agent Properties
window that appears, choose Automatic
from the Startup type:
dropdown and click Start
from Service status:
. Make sure it now says Service 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 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
ssh-agent
by issuing the ssh-add
command and entering your passphrase:ssh-add $HOME/.ssh/your_file_name
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With