Skip to content

Is Your SSH Connection Post-Quantum?

Published:

To check if your SSH connection is post-quantum, run:

ssh -v -p <port> user@<server> exit 2>&1 | grep 'kex: algorithm'

With Apple’s built-in ssh on macOS, you’ll likely see this:

debug1: kex: algorithm: ecdh-sha2-nistp256

That’s not post-quantum.

Why it matters

The key exchange (kex) is how your machine and the server agree on the key that encrypts the session. ecdh-sha2-nistp256 uses elliptic curves, which a large enough quantum computer could break. Nobody can do that today, but anyone who records your traffic now can decrypt it later, once they can. That’s called “harvest now, decrypt later”.

A post-quantum kex combines a classic method with a quantum-resistant one, so an attacker would have to break both. OpenSSH supports two:

Algorithm Post-quantum part Since
sntrup761x25519-sha512@openssh.com Streamlined NTRU Prime OpenSSH 9.0 (default)
mlkem768x25519-sha256 ML-KEM, the NIST standard OpenSSH 9.9 (default since 10.0)

Either one is fine. ML-KEM is the newer, standardized one.

Why a Mac picks the classic one

Two things are going on:

  1. Apple’s ssh is old. Check it with ssh -V. Mine is OpenSSH_9.8p1, which supports sntrup761 but not ML-KEM.
  2. Apple’s build puts ecdh-sha2-nistp256 first. In SSH, the client’s preference order wins, so as long as the server supports it, that’s what you get.

You can see your client’s order with:

ssh -G <server> | grep -i kexalgorithms

If ecdh-sha2-nistp256 comes first, you’re affected. There are two ways to fix it. Pick one.

Method 1: Apple’s ssh

No install. You only change the preference order.

Add this to the end of ~/.ssh/config (create the file if it doesn’t exist):

Host *
  KexAlgorithms sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256

Don’t add mlkem768x25519-sha256 here. Apple’s 9.8 doesn’t know it and will refuse to connect with a Bad SSH2 KexAlgorithms error.

Run the check again:

debug1: kex: algorithm: sntrup761x25519-sha512@openssh.com

Post-quantum.

Method 2: Homebrew’s ssh

This gets you a current OpenSSH with ML-KEM.

  1. Install it:

    brew install openssh
  2. Make sure it’s the ssh your shell runs:

    which ssh

    If that prints /usr/bin/ssh, Apple’s is still first. Add this to ~/.zshrc and open a new terminal:

    export PATH="/opt/homebrew/bin:$PATH"

    which ssh should now print /opt/homebrew/bin/ssh, and ssh -V should show 10.x.

  3. Add this to the end of ~/.ssh/config:

    Host *
      KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512@openssh.com,curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256

    OpenSSH 10 already prefers ML-KEM, so this line is optional. I keep it so the order is explicit.

Run the check again:

debug1: kex: algorithm: mlkem768x25519-sha256

Anything that runs /usr/bin/ssh by its full path, or a GUI app that doesn’t read your shell’s PATH, still uses Apple’s ssh. That’s another reason to keep a ~/.ssh/config line that both versions accept, which is what Method 1 is.

If it’s still not post-quantum

The client offers, but the server has to support it too. If you still see curve25519-sha256 or ecdh-sha2-* after these changes, the server’s OpenSSH is older than 9.0. Check it on the server with ssh -V and update it. On Debian or Ubuntu:

sudo apt update && sudo apt upgrade openssh-server
Node2Shell: What We Patched and What We Learned