Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fixed: No Matching Key Exchange Method Found

· 4 min read · Home Tech

In this article
  1. What Causes This Error
  2. How to Fix It on the Client (Quick Workaround)
  3. How to Fix It on the Server (Better Long-Term)
  4. Checking Which Algorithms Are Supported
  5. Common Misconception: It’s Not About the Cipher
  6. Security Considerations
  7. Frequently Asked Questions

If you see “no matching key exchange method found” when connecting via SSH, it means your client and server could not agree on a key exchange algorithm. The fix is to enable a compatible key exchange method on either side, usually by updating your SSH client or server, or by explicitly allowing an older algorithm in your SSH configuration.

What Causes This Error

SSH uses a negotiation process where the client and server each offer a list of supported key exchange (KEX) algorithms. The first algorithm that appears in both lists is used. If there is no overlap, the connection fails with “no matching key exchange method found.” This typically happens when:

  • The server runs an older SSH implementation that only supports legacy algorithms like diffie-hellman-group1-sha1 or diffie-hellman-group14-sha1.
  • The client is newer and has disabled those older algorithms for security reasons (e.g., OpenSSH 7.0+ disables diffie-hellman-group1-sha1 by default).
  • The client is older and does not support the modern algorithms the server offers (e.g., curve25519-sha256).

How to Fix It on the Client (Quick Workaround)

The fastest way to connect is to tell your SSH client to use a specific key exchange algorithm. This is done with the -oKexAlgorithms option. For example, if your server only supports diffie-hellman-group14-sha1, run:

ssh -oKexAlgorithms=diffie-hellman-group14-sha1 user@host

If you need to use this regularly, add it to your ~/.ssh/config file:

Host myhost
    HostName example.com
    User myuser
    KexAlgorithms diffie-hellman-group14-sha1

This is a temporary fix. It works, but it weakens security by using an older algorithm. Use it only if you cannot update the server.

How to Fix It on the Server (Better Long-Term)

The proper fix is to update the SSH server so it supports modern key exchange algorithms. On most Linux servers, this means updating the openssh-server package. For example, on Ubuntu or Debian:

sudo apt update && sudo apt upgrade openssh-server

After updating, restart the SSH service:

sudo systemctl restart ssh

If you cannot update, you can enable older algorithms in the server configuration. Edit /etc/ssh/sshd_config and add a line like:

KexAlgorithms +diffie-hellman-group14-sha1

The + sign appends the algorithm to the default list. Then restart SSH. This is only a stopgap; you should plan to upgrade the server eventually.

Checking Which Algorithms Are Supported

To see what your client supports, use:

ssh -Q kex

To see what the server supports, use:

ssh -Q kex -oKexAlgorithms=? user@host

Alternatively, you can run nmap --script ssh2-enum-algos -p 22 host to list the server’s algorithms. This helps you identify exactly which algorithm to enable.

Common Misconception: It’s Not About the Cipher

People often confuse key exchange with the symmetric cipher (like AES) or the MAC algorithm. The error specifically mentions “key exchange method,” so changing the cipher (-c) or MAC (-m) will not help. You must adjust the KexAlgorithms setting.

Security Considerations

Older key exchange algorithms like diffie-hellman-group1-sha1 are considered weak because they use a 1024-bit prime and SHA-1. Enabling them exposes your connection to potential attacks. If you must use them, do so only on trusted networks and for a short time. Prefer algorithms like curve25519-sha256, diffie-hellman-group16-sha512, or ecdh-sha2-nistp256.

Frequently Asked Questions

Why does this happen with Git or rsync over SSH?

Git and rsync use SSH under the hood, so they inherit the same key exchange negotiation. If your SSH client fails, these tools will also fail. The same fixes apply: use GIT_SSH_COMMAND="ssh -oKexAlgorithms=..." or set the option in your SSH config.

Can I fix this without changing the server?

Yes, you can force the client to use a specific algorithm with -oKexAlgorithms or the config file. This is the quickest workaround, but it may reduce security. It’s best to update the server if possible.

What if the server doesn’t support any modern algorithm?

If the server is very old, it might only support diffie-hellman-group1-sha1. You can enable that on the client, but be aware it’s insecure. Consider upgrading the server or using a different remote access method (like a VPN) if security is a concern.

How do I permanently add a key exchange algorithm on Windows (PuTTY)?

In PuTTY, go to Connection > SSH > Kex and check the algorithms you want to allow. Move them up or down to change priority. Then save the session. This applies to PuTTY only; the OpenSSH client on Windows uses the same -oKexAlgorithms option.

Is there a way to see the exact error details?

Yes, run SSH with -v (verbose) to see the negotiation process. It will show which algorithms the client offers and which the server returns. This helps you pinpoint the mismatch.