I used puttygen.exe on Windows 10 to generate private and public keys. I saved that keys in C:\Users\Alexander\.ssh\
Public key was added to remote repo (Not by me. I don't have an access).
Then I used command in Git Bash:
git clone git@ipaddress:project_name.git
And I got an error:
key_load_public: invalid format
Permission denied (publickey).
fatal: Could not read from remote repository.
Example keys (generated for just for example)
id_rsa.ppk
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20170110
Public-Lines: 6
AAAAB3NzaC1yc2EAAAABJQAAAQEAx0UhtZcgUT5XpoNlcoVFGHbArEsARQVCv5m0
TRh90Xq15gxOvL+x7I0B29xOuOP054RtQaOzHqnKUzpMdrIoZFkYEYJ11p42kC05
PVR/CwtKBuONJZzoIveJlNG1IhbC3G8DMZD5j68T5OVbCqftHMIBe4CTr7TewJ9T
/lmSZPytWXk/Xtcvn1i1TQZS2ShtSNOwtx77fLzkVmC6F4uM2JgJ9bSM2xQZTX/j
DYZTtoEsmyBadANAEZx4kQAoITwxXVRPBPJnB74EdSMXNhrDBJ+sZSEy7kxmc3a/
UK6CzdN3wiEMd/Bb1nuzR2cpWrWhniG66lnOTJb3sF8iiVtw7Q==
Private-Lines: 14
AAABAEtmRBsyQ5RcxzgWCrW14sr8gEExIrJVBH/ZSyQXGtmkDXmjysP1gZfGpsHk
qCpIaoEdWcXPPNsrfPzloGRDaTq57W5otvdCyImUkjLhs4ejaB5IQz6qEqVya2i+
DS9+O+S0YhLBO9WAhBFrijtiIl3oivB11wQ2mXlRCwZLZ9MugQ3rPfS0O/E2asrO
+MyiR2uv84lVb2wUT0Be3eeubnT2Qp8CoX3qV93LwBM053tepmD0jtSBsaXepADw
mdjBfIkUm+z/69PKtsEoYtIRe5DQRGQhUrwZasJnrfwAvdkr56NKM/rEL0ocUPDX
pXQalD88fKHKog5pr25c8aImklUAAACBAPmqhoRBWy+VJxgZ2BeMYv2PbmQCrQyp
ZVqua9byU59cANjarPcEb1zSUVEJyO8KlTW1eiTeMrya3cdrqbk3Rhp8XgolRsrv
ZK2rMQxP5nIoHyndtG1CCVqrWnwjIsb4r4cq2aBaUWjQJ+ofpiUHVkHev+h58zEA
zpDZs0Jrv5n7AAAAgQDMU04pqQ1hnv050gs8C2Gy+DjbW8b/NbQl64x0HFik/lWB
CRLrCd341ZQWY0PcU5ZjwNa8GwwJZPJI2bX84/a7dq2ENnT1+uYqpuK8lnPTcBDy
WjlGcf/fWJyJpdLqqXkMZ7or4k9ReVIXz9A8xRkhGEH2xM8Vk2fyoLY88RFUNwAA
AIA+zxdPdF8dPr8HwTJ5Pb0NQjl2likOxR24QmqxlCu/bD1p8R1tZzX5Jh2HP2on
RO+KVLYHzNKqtKRZW/MHftYcm6AvYLhP7hxG/tFoNM9lEmsqdJenxaWP745LP9Pc
k3qh7kC4KfTXyfgsd+C6dXzqhAokz81zL41QtyJxlQzR2w==
Private-MAC: ce79771084cbabf61fc2bf3b1403e42a9957e2af
id_rsa.pub
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20170110"
AAAAB3NzaC1yc2EAAAABJQAAAQEAx0UhtZcgUT5XpoNlcoVFGHbArEsARQVCv5m0
TRh90Xq15gxOvL+x7I0B29xOuOP054RtQaOzHqnKUzpMdrIoZFkYEYJ11p42kC05
PVR/CwtKBuONJZzoIveJlNG1IhbC3G8DMZD5j68T5OVbCqftHMIBe4CTr7TewJ9T
/lmSZPytWXk/Xtcvn1i1TQZS2ShtSNOwtx77fLzkVmC6F4uM2JgJ9bSM2xQZTX/j
DYZTtoEsmyBadANAEZx4kQAoITwxXVRPBPJnB74EdSMXNhrDBJ+sZSEy7kxmc3a/
UK6CzdN3wiEMd/Bb1nuzR2cpWrWhniG66lnOTJb3sF8iiVtw7Q==
---- END SSH2 PUBLIC KEY ----
What may be wrong here?
Always use the "git" user $ ssh -T [email protected] > Permission denied (publickey). If your connection failed and you're using a remote URL with your GitHub username, you can change the remote URL to use the "git" user. You should verify your connection by typing: $ ssh -T [email protected] > Hi USERNAME!
"Permission denied (publickey)" and "Authentication failed, permission denied" errors occur if: You're trying to connect using the wrong user name for your AMI. The file permissions within the operating system are incorrect on the instance. The incorrect SSH public key (.
The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository. To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git.
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:
~/.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
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