SSH "no matching key exchange method" and "no matching host key type" errors
What "no matching key exchange method" and "no matching host key type" mean, how to read the "Their offer" list, and what to do about an old server.
At the start of every SSH connection the client and the server each send lists of algorithms. They must share at least one choice in every list. If they share none, the connection stops with a message such as:
Unable to negotiate with legacyhost: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1
Unable to negotiate with legacyhost: no matching host key type found. Their offer: ssh-dss
What the message tells you
There are four lists, and the message names the one that failed:
- no matching key exchange method: how the two sides agree on session keys (
KexAlgorithms) - no matching host key type: how the server proves who it is (
HostkeyAlgorithms) - no matching cipher: how the connection is encrypted (
Ciphers) - no matching MAC: how changes in traffic are detected (
MACs)
Their offer is the list the server sent. If the list holds only old algorithms, the server is the problem. OpenSSH does not turn off an algorithm unless it is known to be weak, so an offer made of only diffie-hellman-group1-sha1 or ssh-dss means the server software is out of date. Newer OpenSSH versions leave these algorithms off by default.
Fixes
The best fix is on the server: upgrade the software, or change it to offer a current algorithm and key type. This is usually a job for the person who runs the host, such as a network or router administrator. Send them the exact message.
If you must connect before that is done, OpenSSH on a computer can switch on one old algorithm for one host. The + adds it to the defaults instead of replacing them:
ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 user@legacyhost
ssh -oHostKeyAlgorithms=+ssh-dss user@legacyhost
The same can be written in ~/.ssh/config:
Host legacyhost.example.com
KexAlgorithms +diffie-hellman-group1-sha1
HostkeyAlgorithms +ssh-dss
OpenSSH describes this as a temporary measure. The algorithms were turned off because they are weak.
ssh-rsa and SHA-1
OpenSSH 8.8 (September 2021) stopped using RSA signatures with the SHA-1 hash by default. Existing RSA keys still work: OpenSSH has supported the stronger RSA signatures with SHA-256 and SHA-512 since version 7.2. The change causes trouble only with older SSH software that cannot use them. For a single old host, OpenSSH documents this stopgap:
Host old-host
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
An old server may also list a key in authorized_keys that it will not accept, because PubkeyAcceptedAlgorithms (called PubkeyAcceptedKeyTypes in older versions) is a separate list from the connection lists above. Sign-in then fails even though the key looks correct. See Authorized keys and permissions.
If the connection starts but key login fails with sign_and_send_pubkey: no mutual signature supported, see SSH "sign_and_send_pubkey: no mutual signature supported".
Checking what your client supports
ssh -Q kex key exchange algorithms
ssh -Q key public key types
ssh -Q cipher ciphers
ssh -Q mac MACs
ssh -G host the settings ssh will use for that host
If the connection works but prints "connection is not using a post-quantum key exchange algorithm", see SSH "connection is not using a post-quantum key exchange algorithm".
In an app
This app's SSH profile screen has no setting for key exchange, host key, cipher or MAC lists. If a server offers only old algorithms and the app cannot connect, the fix is on the server. Keep the exact error text for the host's administrator.
Related
- SSH: how it works
- Key types and formats
- Known hosts and fingerprints
- SSH problems
- SSH error messages, what each one means
- SSH "sign_and_send_pubkey: no mutual signature supported"
- SSH "Corrupted MAC on input" and "message authentication code incorrect"
- SSH "connection is not using a post-quantum key exchange algorithm"