Connecting from a Linux Mint 21 LAB-PC to a Cisco 1941 router using SSH gives a "no matching key exchange method found" error. Notice that the router gives a "No matching cipher found" error, which is different than the error on the LAB-PC! (Nevermind the date/time settings on switch and router, they are a bit off as I set them manually)
guru@lab:~$ ssh -l admin 192.168.10.254
Unable to negotiate with 192.168.10.254 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,
diffie-hellman-group14-sha1
guru@lab:~$
R1#
Jul 9 11:25:38.179: %SSH-3-NO_MATCH: No matching cipher found: client aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc server aes25
6-cbc
R1#
Cipher list.
Via this post, we already know how to fix that cipher error on the "server side". Here, we will use a cipher on the Linux client that the server (R1) understands. Now we are left with "no matching key exchange method found" error on both sides.
# By default, the SSH client speaks these Ciphers
guru@lab:~$ grep "Cipher" /etc/ssh/ssh_config
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# Make the SSH client speak a cipher that the router understands
guru@lab:~$ ssh -c aes256-cbc -l admin 192.168.10.254
Unable to negotiate with 192.168.10.254 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,
diffie-hellman-group14-sha1
guru@lab:~$
S1#
R1#
Jul 9 12:43:57.403: %SSH-3-NO_MATCH: No matching kex algorithm found: client curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-n
istp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,sntrup761x25519-sha512@openssh.com,diffie-hellman-group-exchange-sha256,diffie-hellman-gro
up16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c,kex-strict-c-v00@openssh.com server diffie-hellman-gr
oup-exchange-sha1,diffie-hellman-group14-sha1
R1#
Key exchange
There is a discrepancy between the key exchange algorithms shown in the output of ssh -Q kex and those observed during the actual SSH negotiation with ssh -vvv. The algorithms listed in ssh -Q kex include all supported algorithms, but some may be deprecated or considered less secure. During actual connections, OpenSSH may prioritize more secure algorithms.
R1#show ip ssh
SSH Enabled - version 1.99
Authentication methods:publickey,keyboard-interactive,password
Authentication Publickey Algorithms:x509v3-ssh-rsa,ssh-rsa
Hostkey Algorithms:x509v3-ssh-rsa,ssh-rsa
Encryption Algorithms:aes128-ctr,aes192-ctr,aes256-ctr
MAC Algorithms:hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-sha1-96
KEX Algorithms:diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
...
Solution and new problem
The Linux client (LAB-PC) has to use a key exchange algorithm that the server (R1) supports; either diffie-hellman-group-exchange-sha1 or diffie-hellman-group14-sha1 in this case. Let's use the first one. Now we get the error "no matching host key type found".
guru@lab:~$ ssh -c aes256-cbc -oKexAlgorithms=+diffie-hellman-group-exchange-sha1 -l admin 192.168.10.254
Unable to negotiate with 192.168.10.254 port 22: no matching host key type found. Their offer: ssh-rsa
guru@lab:~$
R1# Jul 9 13:17:59.767: %SSH-3-NO_MATCH: No matching hostkey algorithm found: client ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256-c
ert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.co
m,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-ed25519,ecdsa-sha2
-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-25
6 server ssh-rsa
R1#
Host key type
There is a discrepancy between the host key types shown in the output of ssh -Q key and those observed during the actual SSH negotiation with ssh -vvv. The algorithms listed in ssh -Q key include all supported key types, but during actual connections, OpenSSH may prioritize more secure key types.
guru@lab:~$ ssh -c aes256-cbc -oKexAlgorithms=+diffie-hellman-group-exchange-sha1 -o HostKeyAlgorithms=+ssh-rsa -l admin 192.168.10.254
The authenticity of host '192.168.10.254 (192.168.10.254)' can't be established.
RSA key fingerprint is SHA256:X+55b1YqibQQ6qlzHP/DxeEbUQ7b1J8k9z78syYa3bY.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.10.254' (RSA) to the list of known hosts.
(admin@192.168.10.254) Password:
R1#