Excellent question. This is a very common issue that happens when a modern Linux system (with an up-to-date OpenSSH client) tries to connect to an older Cisco device (running an older IOS, IOS-XE, or NX-OS).
Here's a detailed breakdown of why this happens and how to fix it, from the most secure to the least secure method.
The Core Problem: A Failed Negotiation
When you initiate an SSH connection, the client (your Linux machine) and the server (the Cisco device) go through a negotiation process. One of the first and most critical steps is agreeing on a Key Exchange (KEX) algorithm.
Your Linux Client says: "Hello! To securely establish a connection, I support these modern, strong KEX algorithms: [algo-A, algo-B, algo-C]."
The Cisco Device says: "Hello! I'm a bit older, and I only support these KEX algorithms: [algo-X, algo-Y]."
The error "no matching kex algorithm found" occurs because there are no algorithms in common between the two lists. For security, the connection is immediately terminated.
The Most Common Cause: Deprecated Algorithms
The most frequent reason for this is that modern OpenSSH (on your Linux machine) has disabled old and insecure algorithms for your protection. The Cisco device, especially if its IOS hasn't been updated in years, likely only offers algorithms that are now considered weak, such as:
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1 (SHA1 is the weak part)
Your Linux client has deprecated these and will refuse to use them by default.
How to Fix It (From Best to Worst Solution)
Method 1: The Best and Most Secure Solution (Upgrade Cisco IOS)
The root cause is that the Cisco device is using outdated, insecure cryptography. The best fix is to address the problem at its source.
Check Cisco IOS Version: Log into your Cisco device via the console or Telnet (if it's enabled) and run show version.
Upgrade the IOS: Find a modern version of the IOS/IOS-XE software for your hardware model. Newer versions support stronger KEX algorithms (ecdh-sha2-*, diffie-hellman-group-exchange-sha256, etc.), ciphers (like aes256-ctr), and MACs that will be compatible with your Linux client out-of-the-box.
Why this is the best: You fix the security vulnerability and ensure future compatibility without weakening your client.
Method 2: The Good Solution (Enable Stronger Algorithms on Cisco)
Sometimes the Cisco IOS version is new enough to support stronger algorithms, but they aren't enabled or prioritized. You can try to configure this.
Check Supported Algorithms on the Cisco:
You can try to see what the device is capable of by using this command in configuration mode:
cisco
conf t
ip ssh server algorithm kex ?
This will show you the available KEX algorithms you can enable.
Enable Modern Algorithms:
Enter configuration mode (conf t) and configure SSH to use a list of modern, secure algorithms.
cisco
! Enter global configuration mode
conf t
! Configure modern KEX algorithms (prioritized by order)
ip ssh server algorithm kex ecdh-sha2-nistp521 ecdh-sha2-nistp384 ecdh-sha2-nistp256 diffie-hellman-group-exchange-sha256 diffie-hellman-group16-sha512
! Also a good idea to update your Ciphers and MACs at the same time
ip ssh server algorithm encryption aes256-ctr aes192-ctr aes128-ctr
ip ssh server algorithm mac hmac-sha2-512 hmac-sha2-256
! Exit configuration mode
end
! Save the configuration
write memory
Now, try connecting from your Linux client again. It should be able to negotiate a secure algorithm.
Method 3: The Workaround (Temporarily Weaken Your Linux Client)
WARNING: This method reduces the security of your SSH connection to this specific device. Do this only if you cannot update the Cisco device.
You will tell your Linux SSH client to explicitly allow one of the older algorithms that the Cisco device offers.
Step 1: Find out what the Cisco device offers.
Run your SSH command with the verbose (-v) flag. This will show you the negotiation details.
bash
ssh -v user@cisco-device-ip
Look for a line in the debug output that looks like this:
code
debug1: kex: server->client ... no match: [server's offered algos] vs [client's offered algos]
debug1: Unable to negotiate with 192.168.1.1 port 22: no matching key exchange method found.
debug1: Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
The key part is "Their offer". This tells you what the Cisco device supports. In this example, it's diffie-hellman-group1-sha1.
Step 2: Connect using the weaker algorithm.
You can now use the -o option to add that algorithm for a single connection.
bash
# The '+' adds the algorithm to the client's list of allowed methods
ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 user@cisco-device-ip
Note on other potential errors: If you fix the KEX algorithm, you might immediately get another error like "no matching cipher found" or "no matching MAC found". The old device likely also uses old ciphers (like aes128-cbc) and MACs (hmac-sha1). You can add them in the same way:
Method 4: The Permanent Workaround (Configure your Linux Client)
If you need to connect to this old device regularly, adding the options on the command line every time is tedious. You can add a permanent configuration for this host in your ~/.ssh/config file.
Edit the file ~/.ssh/config (create it if it doesn't exist).
Add a new host entry. This is the recommended way to create a permanent exception, as it only affects connections to this one device.