Git clone. key_load_public: invalid format Permission denied (publickey)

Git is using OpenSSH and it does not support PuTTY key formats. You need to convert it to OpenSSH format. This was described in SO documentation, now in the answer to Not able to add SSH key in Jenkins configuration:

  • Open PuttyGen
  • Click Load
  • Load your private key
  • Go to Conversions->Export OpenSSH and export your private key
  • Copy your private key to ~/.ssh/id_rsa

Sorry for answering an old question, but the listed solutions didn't help. Here's what worked for me:

Git may not be using the correct SSH client for outgoing connections.

I was having a similar issue and ended up finding an answer that set me on the right track to fix it. From what I understand, both Git & My command line where generating key-pairs using openssh, but Git was attempting to open them using it's own SSH client.

I'm not sure why Git would use two different ssh clients, one for generating, one for connecting, but this was evidenced by being able to verify my key by opening an SSH session to GitHub, but not connect to a repository. A further check seemed to validate the theory:

C:\where ssh
C:\Windows\System32\OpenSSH\ssh.exe

And in git bash:

$ where ssh
C:\Program Files\Git\usr\bin\ssh.exe

While trying the commands listed in the answer didn't fix my problem, they led me on a much more successful google search that got me to this GitHub comment, which contained the following single line command, to be run in git bash:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

This command will not output anything if it works, but it will set git to use the ssh client packaged with windows instead of the one included with git. After running this command, Git worked flawlessly for me.

Weirdly enough, running "where ssh" in git bash now returns two paths, but it doesn't seem to be causing any more issues:

$ where ssh
C:\Program Files\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe

Tags:

Git

Ssh