15

Continuation of issue here: I'm trying to set up my first Git Repository on GitHub. (Note, this means I can't use putty, I'm using openssh, or at least I'm supposed to and I think I am). I've been following the documentation on GitHub's website here. I get everything right up until the very last command: git push -u origin master. It gives me the following error:

The server's host key is not cached in the registry.
You have no guarantee that the server is the computer you think it is.
The server's rsa2 key fingerprint is: ssh-rsa 2048
16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
Connection abandoned. fatal: The remote end hung up unexpectedly

I'm guessing this means that in my known_hosts file their ssh-rsa key isn't found, but I'm not sure how to fix that. I've tried ssh -T git@github.com and I log on just fine. I've also tried closing the git bash and re-opening in case it's a cache issue. This doesn't fix the problem. This is the only output I get that differs from what the documentation indicates. I'm hoping to put up a sweet Java Helper Library, so any help would be greatly appreciated!

Community
  • 1
  • 1
kentcdodds
  • 20,934
  • 27
  • 99
  • 178
  • Weird... just like http://stackoverflow.com/questions/10156356/github-the-remote-end-hung-up-unexpectedly/10156776#comment13041705_10156776 . Same question: does `$HOME/ssh/known_hosts` exists? Is `$HOME` (or `%HOME%` in a `git-cmd.bat` DOS session) well defined? (as illustrated in http://stackoverflow.com/questions/10122439/msysgit-and-ssh-config-missing/10122865#10122865) – VonC Apr 15 '12 at 21:33
  • Why do you think you can't putty? Are you sure ssh-agent is running? I've used both Plink.exe and ssh.exe to connect to Github. Post your .git/config if you could. – Andrew T Finnell Apr 15 '12 at 21:34
  • Also, do you happen to have GIT_SSH environment variable set? – Andrew T Finnell Apr 15 '12 at 21:44
  • 1
    Thanks for the quick responses. `known_hosts` does exist and the first thing in it is: `github.com,207.97.227.239 ssh-rsa.....` so yeah... I can't use PuTTY because in their documentation it says: "Do not use PuTTY if you are given the option. GitHub only provides support for openssh." Also, I do have my GIT_SSH environment variable set. It's pointing to plink.exe... yeah, I don't really know what I'm doing. I downloaded that from the PuTTY website. I'm guessing that has something to do with it... What's an alternative I could use? – kentcdodds Apr 15 '12 at 22:02
  • 1
    Plink is "a command-line interface to the PuTTY back ends", which might mean your GIT_SSH environment is still PuTTYfied... – cfedermann Apr 16 '12 at 06:07
  • I just encountered this 5 minutes ago so in case anyone hits this via Google, the problem is that if you're using git+plink to access github and you use ssh from within cygwin/msys/whatever then those have a different known_hosts file. Use putty to connect to github and it will store the server's fingerprint. After doing that, using pageant+plink+git will work fine assuming you've set up your GIT_SSH environment and that pageant is running and has the correct keys. – Jeff Tucker Jun 05 '15 at 23:51

5 Answers5

15

Using git-for-windows with GIT_SSH pointing to plink.exe, opening a putty to the server and accepting the host key (and then killing the putty session, not even proceeding with logging in) was enough to solve this issue for me.

Name
  • 151
  • 1
  • 2
6

On Windows, it seems that sometimes you don't get to actually accept a server's host key.

Try one of the following commands from the Power Shell:

ssh github.com

Or

plink.exe -agent github.com

Run these standalone and press y when asked to accept the host key.

Use ssh-add to add your private key to the current Power Shell session:

C:> ssh-add PATH\TO\PRIVATE\KEY

Afterwards, you should be able to successfully run git push.

Source: http://help.github.com/ssh-issues/

cfedermann
  • 3,110
  • 17
  • 23
  • `ssh github.com` gives me a `Permission denied (publickey)` and the `plink.exe -agent github.com` asks me whether I want to store the key in the chache. I say yes, then it says `login as:` and I tried my github username and also nothing and both gives me a `No supported authentication methods available` error. Note, in this session I've successfully authenticated with `ssh -T git@github.com`. I'm at a total loss... – kentcdodds Apr 16 '12 at 23:11
  • Haha, sorry about that, I should have explained what happens when I try to push. Now, when I try `git push -u origin master` I get `FATAL ERROR: Disconnected: No support authentication methods available (server sent: publickey)` and disconnects. – kentcdodds Apr 17 '12 at 13:54
  • Thanks for the edit. Unfortunately, when I try to add the private key generated from Git Bash, pageant gives me `Can't load this key (OpenSSH SSH-2 private key)`. Just for kicks, I tried the public key file and it says `Couldn't load this key (not a private key)`. When I try to add a key, the file it's looking for is a `PuTTY private key file (*.ppk)`. My private key generated by the Git Bash doesn't have a file extension and the public key has a pub extension... Also, I'm pretty sure my private key is supposed to be OpenSSH not PuTTY (per the github.com documentation). – kentcdodds Apr 17 '12 at 14:10
6

The ideal solution would be (if you really don't need to use plink in git) removing the GIT_SSH environment variable and generating a new keypair with command ssh-keygen -t rsa -C "youremail" on Git Bash then change your ssh key in github because from what I've understood from the comments is putty and openssh is conflicting.

However, if you still want to use plink you can use PuTTYgen to generate a PuTTY format key then change your public key in github and load your private key in PuTTYagent then you should do a connect to github.com with PuTTY this would add githubs fingerprint to known_hosts and you are good to go. This would be a resource to github with PuTTY http://nathanj.github.com/gitguide/tour.html

Learath2
  • 15,755
  • 2
  • 18
  • 30
  • I removed the environment variable (because if GitHub is telling the truth I can only use OpenSSH) and tried creating a new keypair. I successfully added it to my account on GitHub and authenticated with `ssh -T git@github.com` but when I tried calling `git push -u origin master` it gave me the `No supported authentication methods available` error again. I'm guessing this is because I don't have an alternative to plink.exe in my environment variables, but... yeah, how do I give a supported authentication method using OpenSSH? – kentcdodds Apr 17 '12 at 14:59
  • I don't have a GIT_SSH variable aswell mine works just fine its not the case can you try running that command in verbose mode `git push -vu origin master` that would output some debug info about what really failed. – Learath2 Apr 17 '12 at 15:28
  • The only change was before it outputted the error it outputted: `Pushing to git@github.com:kentcdodds/Java-Helper.git` – kentcdodds Apr 17 '12 at 15:34
  • If ssh git@github.com works and push doesnt there is only one explaination git is somehow still using plink.exe either reinstall msysgit with openssh selected or do `cd ~` then `echo "GIT_SSH="/usr/bin/ssh.exe"" > .profile` and restart the git bash – Learath2 Apr 17 '12 at 16:06
  • Ha! It worked! I have no idea how, but it worked! Haha, thanks a ton. Hopefully I can get this setup with Netbeans now so I don't have to worry about the Bash as much... We'll see. Thanks! – kentcdodds Apr 17 '12 at 16:27
  • No problem if you need help on that just ask ^^ – Learath2 Apr 17 '12 at 16:30
  • Asking... ;) http://stackoverflow.com/questions/10195384/setting-up-github-repo-with-netbeans-ide – kentcdodds Apr 17 '12 at 16:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10185/discussion-between-learath2-and-kentcdodds) – Learath2 Apr 17 '12 at 16:54
  • As per your suggestion, I have removed `GIT_SSH` from the env var. and find that there was another key pointing `plink` with name `SVN_SSH` which was finding ambiguity in accessing `plink`. So thanks your little bit part of solution works for me. I am using assembla git repo in my project. – Sumit Ramteke Aug 18 '14 at 06:13
2

Adding info to the post of @Name (for the sake of completeness), as I just had (again) this issue today.

Putty stores its SSH known hosts in a registry key, not in the ~/.ssh/known_hosts file like SSH. So to make Git work with PLink and Pagent, you just have to start a Putty session on the remote Git server, and accept the key. This way, you won't have the message again.

This is disturbing, as you have to accept the SSH key twice : one for SSH-ing the server, one for Putty/Plink/Pagent, but once you do it, it works like a charm.

Community
  • 1
  • 1
Olivier B.
  • 196
  • 1
  • 1
  • 9
0

This worked for me:

I verified the github fingerprint here: https://help.github.com/en/github/authenticating-to-github/githubs-ssh-key-fingerprints

Once confimed, git didn't asked again.

rundekugel
  • 679
  • 5
  • 17