Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2bam/33347ff54be8088943450f20323fde53 to your computer and use it in GitHub Desktop.
Save 2bam/33347ff54be8088943450f20323fde53 to your computer and use it in GitHub Desktop.
Git For Windows "Permission Denied (publickey)" SSH problem calling `git` from CMD/PowerShell, only accepting id_rsa, asking each time the passphrase.

If you:

  • are using PowerShell or CMD directly
  • don't want to be forced to use id_rsa
  • don't want to input a passphrase on each call to git
  • don't want to use Git Bash because you want to use it from CMD/PowerShell directly you need some troubleshooting to use git installation executables and a prior setup:

1. Start or get currently running agent into env vars (PID and socket/pipe file)

start-ssh-agent.cmd
It should be in PATH, otherwise find it at C:\Program Files\Git\cmd.
This command undocumented in the FAQ will spawn a child CMD with the dynamic env vars set. Use it, if you close it will leave the agent on but git calls won't work as wanted.

2. Make sure you're using the ssh executables from the git installation

In PowerShell: Get-Command ssh (this is like which ssh in Linux)
You're probably not using that, so point there before anything else.
In CMD: set PATH=C:\Program Files\Git\usr\bin;%PATH%
In PowerShell: $Env:PATH = "C:\Program Files\Git\usr\bin;$Env:PATH"

3. Only after that load keys using git installation's ssh-add

ssh-add <PATH_TO_KEY>
And enter the passphrase.

Then you can use git directly from CWD/PowerShell without (so much) troubles. Not only git push but also git clone, etc. I needed this for some automation and didn't want to spawn a Git Bash per git call, neither wanted to run inside Git Bash.

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