Is Your SSH Key Post-Quantum? How To Check And Generate One

· 883 words

I was checking one of my SSH connections with ssh -v and saw this line:

debug1: kex: algorithm: mlkem768x25519-sha256

My first thought was that my SSH key is now post-quantum. It’s not. The connection is post-quantum, but the key I use to log in is still classical. Those are two different things, and in this guide I’ll show you how to check both and how to generate a post-quantum SSH key.

Why Post-Quantum Matters For SSH

A large enough quantum computer could break the cryptography behind RSA, ECDSA and ED25519. That computer doesn’t exist yet, but someone can record your encrypted traffic today and decrypt it later when it does. This is called harvest now, decrypt later.

Post-quantum algorithms like ML-KEM and ML-DSA are standardised by NIST and are designed to resist quantum attacks.

An SSH Connection Has Two Steps

Every SSH connection goes through two separate steps:

  1. Key exchange (kex): the client and server agree on the keys that encrypt the session. This happens before your SSH key is sent.
  2. Authentication: your client proves who you are with your SSH key, e.g. id_ed25519.

The two steps of an SSH connection: key exchange and authentication

The kex: algorithm line only shows step 1. That is why it shows the same algorithm whichever key or account you use. I have both an ED25519 and an RSA key loaded in my agent, and checking with either GitHub account showed mlkem768x25519-sha256 every time.

Check If Your Connection Is Post-Quantum

Run this against any server you use:

ssh -v [email protected] exit 2>&1 | grep 'kex: algorithm'
debug1: kex: algorithm: mlkem768x25519-sha256

If you see mlkem768x25519-sha256 or sntrup761x25519-sha512, your session is post-quantum. Both are hybrids: a post-quantum algorithm combined with the classical X25519, so an attacker would need to break both.

If you see something like curve25519-sha256, it’s classical, and you need to upgrade OpenSSH on whichever side is older. OpenSSH 10 and later use mlkem768x25519-sha256 by default.

You can list the key exchange algorithms your client supports with:

[[email protected] ~]$ ssh -Q kex | grep -iE 'mlkem|sntrup'
mlkem768nistp256-sha256
sntrup761x25519-sha512
[email protected]
mlkem768x25519-sha256

If you don’t want to ever fall back to a classical key exchange, add this to ~/.ssh/config. Servers that support neither algorithm will then fail to connect:

Host *
    KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512

Check Which SSH Key Type You Are Using

For keys loaded in your SSH agent (this works even if the key file isn’t in ~/.ssh):

ssh-add -l
256 SHA256:Xb3k9Qm2...redacted...Lp7w [email protected] (ED25519)

For key files on disk:

for f in ~/.ssh/*.pub; do ssh-keygen -lf "$f"; done

The number at the start is the key size in bits, and the key type is in brackets at the end. Use this table to read it:

Key type Bits Post-quantum?
RSA 2048 / 3072 / 4096 No
ECDSA (nistp256) 256 No
ECDSA (nistp384) 384 No
ECDSA (nistp521) 521 No
ED25519 256 No
ECDSA-SK / ED25519-SK (hardware keys) 256 No
MLDSA44-ED25519 256 shown Yes (hybrid)

Yes, it’s 521 and not 512. The NIST P-521 curve really is 521 bits.

To see which key was actually used to log in to a server:

ssh -v [email protected] 2>&1 | grep -E 'Server accepts key|Authenticated'

Generate A Post-Quantum SSH Key

First check that your OpenSSH client supports a post-quantum key type. I’m running OpenSSH 10.5 on macOS:

[[email protected] ~]$ ssh -V
OpenSSH_10.5p1, LibreSSL 3.3.6
[[email protected] ~]$ ssh -Q key | grep mldsa
[email protected]
[email protected]

If that prints nothing, you need a newer OpenSSH.

Generate the key:

ssh-keygen -t mldsa44-ed25519 -C "[email protected]" -f ~/.ssh/id_mldsa44_ed25519

This is a hybrid of ML-DSA-44 and ED25519, so an attacker would need to break both. You can confirm it with ssh-keygen -lf:

256 SHA256:yjKm/gcU/VsoUM/ng+sRJhDTM/8S4QXGVnUAYwrT8KQ [email protected] (MLDSA44-ED25519)

The 256 only refers to the ED25519 half. The public key is much bigger than you are used to, about 1.9 KB instead of around 100 bytes.

Load it into your agent alongside your existing key. On Linux, drop --apple-use-keychain:

ssh-add --apple-use-keychain ~/.ssh/id_mldsa44_ed25519

What About ML-DSA-65 And ML-DSA-87?

OpenSSH only ships ML-DSA-44. If you try the higher levels:

[[email protected] ~]$ ssh-keygen -t mldsa87-ed25519
unknown key type mldsa87-ed25519
[[email protected] ~]$ ssh-keygen -t mldsa65-ed25519
unknown key type mldsa65-ed25519
Level NIST category Roughly equal to In OpenSSH
ML-DSA-44 2 AES-128 Yes
ML-DSA-65 3 AES-192 No
ML-DSA-87 5 AES-256 No

ML-DSA-44 is enough for SSH login. A login signature only needs to hold during a live connection, unlike code signing where a signature has to stay valid for years.

Rolling It Out Safely

  • Keep your ED25519 key loaded. The server must also support mldsa44-ed25519. Most servers today (Ubuntu LTS, Debian stable) ship an older OpenSSH and will reject the new key, and SSH quietly falls back to your next key.
  • Add the new public key to ~/.ssh/authorized_keys on servers that support it, then confirm with ssh -v host 2>&1 | grep 'Server accepts key'.
  • Check the server version with ssh host 'ssh -V'.
  • GitHub and other Git hosts only accept key types they have added support for. Check their documentation before switching, and keep ED25519 there for now.

The post-quantum key exchange is what protects your recorded traffic today, and if you are on OpenSSH 10 or later you most likely already have it. A post-quantum login key protects against a future attacker forging a login during a live connection, which is a smaller and later risk. Make sure the key exchange is post-quantum first, then add the new key where your servers support it.