# Migrate: SSH key exchange to hybrid

**What is at stake.** Someone who records an SSH session today could read it later if the classic key exchange is ever broken ("store now, decrypt later"). OpenSSH already has post-quantum hybrid key exchange; the usual problem is an old version or a config that pins classic algorithms.

**What OpenSSH does by version** (openssh.com/pq.html, checked 2026-12-03):

| Version | Key exchange |
|---|---|
| 9.0 | Prefers the hybrid `sntrup761x25519-sha512@openssh.com` by default |
| 9.9 | adds `mlkem768x25519-sha256` (ML-KEM hybrid, RFC 10042) |
| 10.0 | `mlkem768x25519-sha256` becomes the default |
| 10.1 | the client warns when a connection does not use post-quantum key exchange (`WarnWeakCrypto` turns the warning off) |

Lines marked "tested here" were run with OpenSSH 10.0p2 on 2026-12-03. "Not run here" means not executed on that machine.

## 1. Check versions

```sh
ssh -V                 # client version (tested here: OpenSSH_10.0p2)
ssh -Q kex             # client algorithms (tested here: lists mlkem768x25519-sha256 and sntrup761x25519-sha512)
sshd -V                # server version, on the server; not run here
```

Windows note (tested here): the built-in `OpenSSH_for_Windows_9.5p2` lists no post-quantum key exchange at all, and its `sshd -t` rejects both `mlkem768x25519-sha256` and `sntrup761x25519-sha512`. Upgrade it before changing the config.

Some upstream releases before 9.0 support the NTRU Prime hybrid. Builds differ. Use `ssh -Q kex` to inspect the client and `sshd -T` to inspect the effective server configuration. Upstream 9.9 added the ML-KEM exchange.

## 2. Change the server config

Find a restrictive line: `grep -rni '^\s*KexAlgorithms' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/` (not run here).

Preferred: delete the `KexAlgorithms` line so the version's default applies (on 10.0+ that default puts `mlkem768x25519-sha256` first).

If a list is required, put the post-quantum names first and keep classic ones after them (not run here):

```
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,curve25519-sha256,ecdh-sha2-nistp256
```

On 9.0 to 9.8 leave out `mlkem768x25519-sha256`; older builds may only know the name `sntrup761x25519-sha512@openssh.com`. `ssh -Q kex` on that machine shows the names it accepts.

Client configs (`~/.ssh/config`, `/etc/ssh/ssh_config`) with a `KexAlgorithms` line get the same treatment.

## 3. Validate before any reload

```sh
sshd -t                                  # syntax and algorithm names; must print nothing and exit 0
sshd -T | grep -i '^kexalgorithms'       # effective list; post-quantum names first
```

`sshd -t` is the safety net: an unknown algorithm name makes it exit non-zero with "Bad SSH2 KexAlgorithms" (tested here on Windows' 9.5p2). Never reload when it fails.

## 4. Reload (the human does this)

Write these for the human (rule 5):

1. Keep one SSH session open the whole time.
2. `sudo sshd -t && sudo systemctl reload ssh` (or `sshd`, depending on the distribution).
3. Open a **second** session to confirm login still works before closing the first.

Rollback: restore the previous `sshd_config` (keep a copy as `sshd_config.pq-shift.bak`), `sshd -t`, reload.

## 5. Prove

- Server side: `python pqshift.py probe host:22 --authorized` lists `mlkem768x25519-sha256` (or `sntrup761x25519-sha512`) first in `kex_algorithms`.
- Client side (not run here against a server): `ssh -v user@host true 2>&1 | grep "kex: algorithm"` shows `kex: algorithm: mlkem768x25519-sha256`.
- An OpenSSH 10.1+ client prints `** WARNING: connection is not using a post-quantum key exchange algorithm.` when it is not.

## Host keys and user keys

Plan signature migration separately from key exchange. OpenSSH 10.6 enables the hybrid `ssh-mldsa44-ed25519` signature algorithm. Check client and server support before adding a new host or user key alongside the current one. Earlier experimental keys use a different format. [OpenSSH 10.6 release notes](https://www.openssh.org/releasenotes.html#10.6)

## Side effects

Larger key-exchange messages. Very old clients, embedded devices and some network appliances only speak classic algorithms; that is why classic names stay in the list. Removing them is a separate, explicit human decision.
