Skip to content

/flags/ssh-protocol/ssh-o-kexalgorithms

ssh -o KexAlgorithms: add, remove or prefer SSH key exchange methods

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
SSH protocol
command
ssh
flag
-o KexAlgorithms=LIST
default
OpenSSH's built-in list; OpenSSH 10.x starts with mlkem768x25519-sha256 and does not include the SHA-1 Diffie-Hellman groups

ssh -o KexAlgorithms=+diffie-hellman-group14-sha1 user@host changes the list of key exchange methods the client offers. The key exchange creates the shared secret that encrypts the session, so if the server supports none of the client's methods the connection stops with no matching key exchange method found. Their offer: .... A value starting with + appends to the default list, - removes from it, ^ moves methods to the front, and a plain list replaces it.

The four forms

ssh -G resolves the option without connecting, so the effect of each form is visible:

bash
kex() { ssh -G "$@" 2>/dev/null | awk '$1 == "kexalgorithms" { print $2 }' | tr ',' '\n'; }
echo "--- default (first three, total):"
kex host.example.org | head -3; kex host.example.org | wc -l
echo "--- +diffie-hellman-group14-sha1 (last entry):"
kex -o KexAlgorithms=+diffie-hellman-group14-sha1 host.example.org | tail -1
echo "--- ^curve25519-sha256 (first entry):"
kex -o KexAlgorithms=^curve25519-sha256 host.example.org | head -1
echo "--- -sntrup761x25519-sha512@openssh.com (still present?):"
kex -o KexAlgorithms=-sntrup761x25519-sha512@openssh.com host.example.org | grep -cx 'sntrup761x25519-sha512@openssh.com'
echo "--- replace with one method:"
kex -o KexAlgorithms=curve25519-sha256 host.example.org
echo "--- unknown name:"
ssh -G -o KexAlgorithms=+no-such-kex host.example.org 2>&1 >/dev/null | tail -1; echo "exit ${PIPESTATUS[0]}"

Output

--- default (first three, total):
mlkem768x25519-sha256
sntrup761x25519-sha512
sntrup761x25519-sha512@openssh.com
12
--- +diffie-hellman-group14-sha1 (last entry):
diffie-hellman-group14-sha1
--- ^curve25519-sha256 (first entry):
curve25519-sha256
--- -sntrup761x25519-sha512@openssh.com (still present?):
0
--- replace with one method:
curve25519-sha256
--- unknown name:
command-line line 0: Bad SSH2 KexAlgorithms '+no-such-kex'.
exit 255

The default starts with the post-quantum hybrid mlkem768x25519-sha256. + adds the old SHA-1 group at the end, so it is used only when the server has nothing better. An unknown name is rejected before any connection is attempted, with exit code 255.

Common methods

MethodStatus in current OpenSSH
mlkem768x25519-sha256Default first choice: ML-KEM-768 hybrid with X25519 (post-quantum)
sntrup761x25519-sha512Post-quantum hybrid with Streamlined NTRU Prime, still enabled
curve25519-sha256Classical default for servers without post-quantum support
ecdh-sha2-nistp256/384/521NIST curves, enabled
diffie-hellman-group-exchange-sha256Enabled; server picks the group size
diffie-hellman-group14-sha256, group16-sha512, group18-sha512Enabled fixed groups (RFC 8268)
diffie-hellman-group14-sha1Supported but disabled by default (SHA-1)
diffie-hellman-group1-sha1Supported but disabled by default; 1024-bit group, Logjam range
diffie-hellman-group-exchange-sha1Supported but disabled by default

ssh -Q kex prints every method your build supports; see list supported algorithms. RFC 9142 lists which methods SSH implementations should and should not use.

Scope legacy methods to one host

~/.ssh/config
Host old-router
    HostName 192.0.2.1
    KexAlgorithms +diffie-hellman-group14-sha1

The OpenSSH project recommends the + form so that the client automatically moves to a better method once the server is upgraded.

Pitfalls

  • One option per negotiation. If the error says no matching host key type found, you need HostKeyAlgorithms; for no matching cipher found, Ciphers (see the cipher error).
  • Replacing the list by accident. KexAlgorithms diffie-hellman-group1-sha1 without + leaves only the weak method and breaks connections to every modern server.
  • Removed methods cannot be re-enabled. If ssh -Q kex does not list a method, no option brings it back; use an older client in a container or upgrade the server.
  • Server configuration. KexAlgorithms in sshd_config uses the same syntax; sshd -T | grep kexalgorithms prints what the server offers, which is the list quoted after Their offer: in the client error.

FAQ

How do I fix no matching key exchange method found. Their offer: diffie-hellman-group1-sha1?

Append the offered method for that host only: ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 user@host, or a KexAlgorithms line in a Host block. The method must be one your ssh supports, which ssh -Q kex lists.

Which key exchange does a modern OpenSSH use?

The first method both sides support from the client's list. Current OpenSSH puts the post-quantum hybrids mlkem768x25519-sha256 and sntrup761x25519-sha512 first, then curve25519-sha256 and the NIST ECDH curves.

Does KexAlgorithms affect the host key or ciphers?

No. Key exchange, host key algorithm, cipher and MAC are negotiated separately, each with its own option and its own no matching ... found error.

Sources