Skip to content

Instantly share code, notes, and snippets.

@mzpqnxow
Last active June 4, 2025 21:10
Show Gist options
  • Select an option

  • Save mzpqnxow/c442c0aded7ef7382bd3c9c097f2a1be to your computer and use it in GitHub Desktop.

Select an option

Save mzpqnxow/c442c0aded7ef7382bd3c9c097f2a1be to your computer and use it in GitHub Desktop.
Enable post-quantum Key Exchange for OpenSSH

Enabling Post-Quantum Key Exchange on OpenSSH >= 8.0

As of version 8.0, OpenSSH supports an experimental post-quantum key exchange using the sntrup4591761x25519-sha512@tinyssh.org key exchange

Step 1: Check to see if you already have support

Only >= 8.0 have support, but some vendors may currently or eventually backport it into 7.9 (though this is unlikely due to refactoring in 8.0)

Check OpenSSH Client

$ ssh -Q kex
diffie-hellman-group1-sha1
diffie-hellman-group14-sha1
diffie-hellman-group14-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group-exchange-sha1
diffie-hellman-group-exchange-sha256
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
curve25519-sha256
curve25519-sha256@libssh.org
sntrup4591761x25519-sha512@tinyssh.org <---- This is what you should be looking for

If sntrup4591761x25519-sha512@tinyssh.org is present in your kex list then your client already supports it and you won't need to upgrade

Check OpenSSH Server

# /opt/openssh-8.1p1/sbin/sshd -T | grep kex
kexalgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,sntrup4591761x25519-sha512@tinyssh.org

Once again, check for the presence of sntrup4591761x25519-sha512@tinyssh.org. If it is present, your server supports it

Step 2: Specify the KEx in Config Files / Command-Line

$ ssh -oKexAlgorithms=sntrup4591761x25519-sha512@tinyssh.org -v user@host
...
debug1: kex: algorithm: sntrup4591761x25519-sha512@tinyssh.org
...

Rather than using the command-line, you can of course add this to your ~/.ssh/config file, or to the system-wide ssh client configuration file, usually /etc/ssh/ssh_config

Host *
  KexAlgorithms=sntrup4591761x25519-sha512@tinyssh.org

If you only want to enable it for a single host, use it inside a different Host block to avoid making it global

END

That's all!

Appendix - Reasonably Complete Build Configuration for OpenSSH 8.x on a Linux System

Grab the OpenSSH 8 package and use the following to quickly build the client and server in isolation for testing, in case your distribution doesn't yet have an OpenSSH 8 package

Install dependencies

sudo apt-get install \
	autotools-dev \
	bc \
	bison \
	build-essential \
	debhelper \
	devscripts \
	dh-autoreconf \
	dh-exec \
	dh-systemd \
	dpkg-dev \
	fakeroot \
	flex \
	libaudit-dev \
	libedit-dev \
	libgtk-3-dev \
	libpam-dev \
	libselinux1-dev \
	libssl-dev \
	libsystemd-dev \
	libwrap0-dev \
	zlib1g-dev

Configure with parameters similary to the Debian default

Note: Choose only one of the XAUTH values depending on whether you want X11Forwarding!

$ export DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
$ export PREFIX="/opt/openssh-8.1p1"
$ export XAUTH="--with-xauth=/usr/bin/xauth"
$ export XAUTH="--without-xauth"
$ ./configure \
	--prefix=/opt/openssh-8.1p1 \
	--sysconfdir="${PREFIX}/etc/ssh" \
	--libexecdir="${PREFIX}/lib/openssh" \
	--with-mantype=doc \
	--with-privsep-path="${PREFIX}/run/sshd" \
	--with-pid-dir="${PREFIX}/run" \
	--with-pam \
	--with-libedit \
	--with-systemd \
	--with-ssl-engine \
	--with-audit=linux \
	${XAUTH} \
	--with-default-path="${DEFAULT_PATH}" \
	--with-superuser-path="${DEFAULT_PATH}" \
	--with-ldflags='-Wl,--as-needed' \
	--with-pie \
	--without-openssl-header-check
$ make -j && sudo make install

Appendix I - Reasonably Complete Build Configuration for OpenSSH 8.x on a Linux System

Grab the OpenSSH 8 package and use the following to quickly build the client and server in isolation for testing, in case your distribution doesn't yet have an OpenSSH 8 package

$ ./configure --prefix=/opt/openssh-8.1p1 --sysconfdir=/opt/openssh-8.1p1/etc/ssh --libexecdir=/opt/openssh-8.1p1/lib/openssh --with-mantype=doc --with-privsep-path=/opt/openssh-8.1p1/run/sshd --with-pid-dir=/opt/openssh-8.1p1/run --with-pam --with-libedit --with-ssl-engine --with-audit=linux --without-xauth --with-default-path=/bin:/sbin:/usr/bin:/usr/sbin --with-superuser-path=/bin:/sbin:/usr/bin:/usr/sbin --with-ldflags='-Wl,--as-needed' --with-pie --without-openssl-header-check
$ make -j && sudo make install

Appendix II - Using Debian package tools to build

$ sudo apt-get update
$ sudo apt-get source openssh-server
$ wget https://ftp4.usa.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.1p1.tar.gz
$ tar -xvzf openssh-8.1p1.tar.gz && cd openssh-8.1p1
$ dpkg-buildpackage -rfakeroot -b
$ cd .. && ls -lrt
$ sudo systemctl stop ssh
$ sudo dpkg -i --force-confold openssh-*.deb
$ sshd -V
#!/bin/bash
# Quick hack to build OpenSSH portable in a way mostly compatible with Debian 12
# Will isntall to /opt/openssh/openssh-<version>/
set -eu
V=10.0p1
PDIR=/opt/openssh/
export DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
export PREFIX="/opt/openssh/openssh-$V"
export XAUTH="--with-xauth=/usr/bin/xauth"
# export XAUTH="--without-xauth"
sudo mkdir -p "$PDIR"
wget -c "https://cloudflare.cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${V}.tar.gz"
tar -xvf "openssh-${V}.tar.gz"
cd "openssh-$V"
./configure \
--prefix="${PREFIX}" \
--sysconfdir="${PREFIX}/etc/ssh" \
--libexecdir="${PREFIX}/lib/openssh" \
--with-mantype=doc \
--with-privsep-path="${PREFIX}/run/sshd" \
--with-pid-dir="${PREFIX}/run" \
--with-pam \
--with-libedit \
--with-systemd \
--with-ssl-engine \
--with-audit=linux \
${XAUTH} \
--with-default-path="${DEFAULT_PATH}" \
--with-superuser-path="${DEFAULT_PATH}" \
--with-ldflags='-Wl,--as-needed' \
--with-pie \
--without-openssl-header-check
make -j
sudo make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment