Skip to content

Instantly share code, notes, and snippets.

@danieldogeanu
Last active February 27, 2025 13:07
Show Gist options
  • Save danieldogeanu/16c61e9b80345c5837b9e5045a701c99 to your computer and use it in GitHub Desktop.
Save danieldogeanu/16c61e9b80345c5837b9e5045a701c99 to your computer and use it in GitHub Desktop.
How to make Powershell remember the SSH key passphrase.

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:

  1. Start the ssh-agent from Windows Services:
  • Type Services in the Start Menu or Win+R and then type services.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, choose Automatic from the Startup type: dropdown and click Start from Service status:. Make sure it now says Service status: Running.
  1. 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
  1. 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
  1. Add your SSH key to the ssh-agent by issuing the ssh-add command and entering your passphrase:
ssh-add $HOME/.ssh/your_file_name
  1. Done! Now restart your Powershell and even Windows if necessary.

If this was useful, you can buy me a coffee here. Thank you!

@N3U2O
Copy link

N3U2O commented Nov 22, 2024

Thank you! Could solve the "FATAL ERROR: No supported authentication methods available (server sent: publickey)
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
failed to run git: exit status 128" symptom with this!

@danieldogeanu
Copy link
Author

Thank you! Could solve the "FATAL ERROR: No supported authentication methods available (server sent: publickey) fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. failed to run git: exit status 128" symptom with this!

You either made a mistake when setting up SSH, or didn't add your public key to GitHub/GitLab, to allow access through SSH. Please follow their tutorial on how to set up SSH, and only follow this tutorial to make PowerShell remember your SSH key. Also, please make sure you're using the repo via SSH, and not HTTPS! Check the remote URL for the repo!

I can't debug for you, but here's what ChatGPT has to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment