10

There's a lot of questions about the following error, but they all have same solution which did not have any effect:

$ git push
Unable to negotiate with 192.168.XXX.XXX: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

There is an article on openssh.com that didn't help. Particularly this was suggested:

... in the ~/.ssh/config file:

Host somehost.example.org
KexAlgorithms +diffie-hellman-group1-sha1

I did exactly that. I assume that ~ resolves to %userprofile% on windows. My file is in C:\Users\MY_USERNAME\.ssh\config:

## use kex algorithm ##
Host 192.168.XXX.XXX
KexAlgorithms diffie-hellman-group1-sha1

The result is that nothing changed. There is also suggestion to use ssh -o but I'm yet to find an answer that bothers to describe how exactly yo do that. I tried this:

$ ssh -oKexAlgorithms=+diffie-hellman-group1-sha1
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]

I need to connect to that GIT repository. I am on windows. The repository uses Gerrit. I also use SourceTree and it has no problems pushing into the repository. So the repository works, but git or openSSH in my bash is broken.

What did I do wrong that this solution didn't work for me?

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • 2
    Try running ssh with the "-vv" flag. It'll print the names of the config files which it reads, and it'll print details of the key exchange. – Kenster Aug 04 '16 at 16:51
  • You say you did the same thing in the config file, but your config file doesn't show that you did. You had `KexAlgorithms diffie-hellman-group1-sha1` but needed `KexAlgorithms +diffie-hellman-group1-sha1`. Notice the `+` before diffie. – Brian Pursley Aug 19 '21 at 13:18
  • @BrianPursley Hah, 5 years later I finally know what I did wrong and why the command in my answer worked. – Tomáš Zato Aug 19 '21 at 13:57

5 Answers5

19

Resolved by using this command I randomly found in some comment thread:

export GIT_SSH_COMMAND='ssh -o KexAlgorithms=+diffie-hellman-group1-sha1'

Must be called every time you open the Git Bash. Yeah, git is hell.

Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
1

I resolved a similar problem on Windows 10 by updating my version of Open SSH to the latest (7.5p1-1) and then making sure that C:Program Files\OpenSSH\bin was the first entry in the system path so it used that ssh.exe and not any others.

Felix Eve
  • 3,811
  • 3
  • 40
  • 50
0

I started getting this error after updating to "git for windows" to version 2.25.1 This algo was deprecated by GitHub in Feb. of 2018.

@Kenster's comment on "use ssh -vv ..." to see where your config files live was key. My home drive in windows is a network drive so my default .ssh folder is on that network volume.

Adding a file called "config" to that folder with:

Host 127.0.0.1
Port 2222
KexAlgorithms +diffie-hellman-group1-sha1

allowed me to connect to my vagrant environment again.

txyoji
  • 6,680
  • 1
  • 44
  • 46
0

I also faced the same issue.Please install the older version of "Git for Windows". https://github.com/git-for-windows/git/releases/tag/v2.17.1.windows.1 This version will solve your issue.

0

I faced the same issue using Git for Windows 2.27.0.

Git for Windows brings its own OpenSSH implementation. I had to change the config file C:\Program Files\Git\etc\ssh_config

Host myhost@example.com
    Port 22
    KexAlgorithms +diffie-hellman-group1-sha1
    KexAlgorithms +diffie-hellman-group14-sha1