Upgrading OpenSSH on Linux 05 dec 2026 | Last updated: 05 dec 2026 00:00

Replace the OpenSSH version that your distro provides with a PQC capable one.

Upgrading OpenSSH on Linux


Linux distros are almost never up-to-date with the latest version of OpenSSH. You can work around this, or bluntly replace the installed binaries with the latest released version.

Danger

You will need to prevent the OS package from overwriting your self-built SSH and keep your self-built OpenSSH up-to-date.

FWIW: FreeBSD ships OpenSSH 10.6p2 as a package. Install openssh-server, sysctl 'sshd_enable="NO"' && sysctl 'openssh_enable="YES"'

Building your own OpenSSH binaries

Prerequisites: GNU make and a C-compiler installed (be it clang or gcc) and zlib headers. On Ubuntu, you'll need build-essentials and zlib1g-dev. On Alpine you need build-base and zlib-dev.

This can all be done as a regular user.

Download the OpenSSH-portable tarball. You can find it on openssh.org/portable Extract the tarball, I usually have these in $HOME/src.

tar xf openssh-10.6p2.tar.gz
cd openssh-10.6p2

The rest of this blog-post assumes you're still in the openssh-10.6p2 directory unless otherwise indicated.

We're building with minimized dependencies, which means throwing out OpenSSL. OpenSSH doesn't need OpenSSL, but that will block (very) old clients. This build will not have RSA or ECDSA key support.

Now, we're at a cross-roads: do we overwrite the base OpenSSH install, or do we install elsewhere and modify the systemd unit or OpenRC script.

  flag OS OpenSSH default Suggested
Binaries --prefix /usr /usr/local /usr/local
Config --sysconfdir /etc/ssh /usr/local/etc /usr/local/etc/ssh

You can mix and match these options, but all of this has impact on later actions.

To overwrite your OS's installation:

./configure --without-openssl --prefix=/usr --sysconfdir=/etc/ssh

To install in the default path (this is used for the rest of this blog-post):

./configure --without-openssl --sysconfdir=/usr/local/etc/ssh

During the configure stage, it will detect optional features and may fail on required libraries. When it succeeds, the end of the output will be something like

configure: creating ./config.status
config.status: creating Makefile
config.status: creating buildpkg.sh
config.status: creating opensshd.init
config.status: creating openssh.xml
config.status: creating openbsd-compat/Makefile
config.status: creating openbsd-compat/regress/Makefile
config.status: creating survey.sh
config.status: creating config.h
config.status: config.h is unchanged

OpenSSH has been configured with the following options:
                     User binaries: /usr/bin
                   System binaries: /usr/sbin
               Configuration files: /etc/ssh
                   Askpass program: /usr/libexec/ssh-askpass
                      Manual pages: /usr/share/man/manX
                          PID file: /var/run
  Privilege separation chroot path: /var/empty
            sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin
                    Manpage format: doc
                       PAM support: no
                   OSF SIA support: no
                 KerberosV support: no
                   SELinux support: no
                   libedit support: no
                   libldns support: no
  Solaris process contract support: no
           Solaris project support: no
         Solaris privilege support: no
       IP address in $DISPLAY hack: no
           Translate v4 in v6 hack: yes
                  BSD Auth support: no
              Random number source:
             Privsep sandbox style: seccomp_filter
                   PKCS#11 support: yes
                  U2F/FIDO support: built-in

              Host: x86_64-pc-linux-gnu
          Compiler: cc
    Compiler flags: -g -O2 -pipe -Wno-error=discarded-qualifiers -Wno-error=format-truncation -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -Wimplicit-fallthrough -Wmisleading-indentation -fno-strict-aliasing -ftrapv -fzero-call-used-regs=used -ftrivial-auto-var-init=zero -fno-builtin-memset -fstack-protector-strong -fPIE
Preprocessor flags:  -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE
      Linker flags:  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie
         Libraries: -lmd
     +for channels:  -lz
        +for FIDO2: -lfido2 -lcrypto
         +for sshd: -lcrypt

Now, we're ready to build (append -j4 if you have 4 CPU cores)

make

An error will show clearly, success isn't as obvious. Last line of output on my build:

...
cc -o ssh-sk-helper ssh-sk-helper.o ssh-sk.o sk-usbhid.o ssherr-nolibcrypto.o -L. -Lopenbsd-compat/  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie  -lssh -lopenbsd-compat -lssh -lopenbsd-compat -lmd  -lfido2 -lcrypto -lz

Preparing for migration your newly built sshd

There's 2 things to consider for replacement. Especially so if you have no other means to access the machine.

Danger

If you are replacing the OS's sshd, it is almost certain that your existing configuration will prevent sshd from starting.

Mistakes do not have to be dramatic, if you take precautions.

  1. As long as you have a running ssh connection to the machine, you're OK. So: keep a running ssh connection to your machine.
  2. Think about backing out of the changes you've made before you start.
  3. Wiping out and reinstalling the distro package (e.g. apt purge openssh-server && apt install openssh-server && dpkg-reconfigure openssh-server).
  4. Or replace your modified systemd unit or RC script (e.g. cp -vf ~/backup/ssh.service /etc/systemd/system/ssh.service).

Running a configuration check is done using the sshd -t command. Run that to verify your config, it will tell you what's wrong with your config (or keys). Don't forget that, depending on earlier choices, the binary to use can be either /usr/sbin/sshd or /usr/local/sbin/sshd. You must test the config with the new binary.

Restart the OpenSSH service, open a new terminal, test establishing a new SSH connection (do NOT disconnect your rescue connection!). Only when you can reliably establish new connections to your new install or configuration disconnect your "rescue" session.

Installing or "packaging"

Crossroads, again.

Is this a local install only? Or do you want to reuse it on multiple systems?

This machine only

Install directly on machine.

Warning

if you've run configure --prefix=/usr that this will overwrite your install

sudo make install

Package for reuse

"Package" your customized build. This can be done with the "overwrite" or the "other directory" method.

mkdir stage
DESTDIR="$PWD/stage" make install
sudo chown 0:0 stage/*
sudo chown --reference /usr/bin/ssh-agent /usr/local/bin/ssh-agent
sudo tar cJf openssh-10.6p2-bin.tar.xz -C "$PWD/stage" .
  1. make install ends with an error as we're not running it as root.
  2. ssh-agent on Ubuntu has a different group _ssh.

Installing the "package"

On any machine, with same OS distro and version, you can untar the package into /.

tar xJf openssh-10.6p2-bin.tar.xz -C /

Modify systemd unit or RC script

This section only applies if you've chosen "different install path" method.

Systemd based systems

For systemd based systems (Debian or RedHat based), use systemctl edit ssh.service to modify the service unit. In the editor (in the correct location near the top!)

### Anything between here and the comment below will become the contents of the drop-in file

[Service]
ExecStartPre=/usr/local/sbin/sshd -t
ExecStart=
ExecStart=/usr/local/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/local/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID

### Edits below this comment will be discarded

Warning

The ExecSstart= is required. Systemd will fail if that's not there.

And reload systemd

systemctl daemon-reload

OpenRC systems

For OpenRC (Alpine Linux), edit /etc/conf.d/sshd. Add to the file:

SSHD_BINARY=/usr/local/sbin/sshd

Update your sshd configuration

To understand OpenSSH configuration, you need to keep in mind that the "first option wins". Command-line -o option=value wins over /etc/ssh/sshd_config containing option=value. If you include config from the main sshd_config (i.e. in /etc/ssh/sshd_configd/*.conf) the order matters too.

Linux's SSH config is all over the place.

  • /etc/default/ssh containing SSHD_OPTS that are used as command-line parameters (Debian and derivatives)
  • "System Wide Crypto Policies" (RedHat and derivatives)
  • /etc/conf.d/sshd (on OpenRC systems like Alpine Linux)

What needs changing depends on how you've configured OpenSSH. If (like we have) you configured with --prefix=/usr/local and --sysconfdir=/usr/local/etc/ssh you get a decent default configuration.

--sysconfdir /etc/ssh

If you have started the ssh service before, there's a good chance that you have ssh_host_*_key files in /etc/ssh. To make full use of PQC, you'll need a new type of key: ML-DSA44-Ed25519 hybrid.

ssh-keygen -t mldsa44-ed25519 -N "" -C "" /etc/ssh/ssh_host_mldsa44_ed25519_key

There may be configurations in your /etc/ssh/sshd_config file or in included files (usually /etc/ssh/sshd_config.d) that will prevent sshd from starting

Testing and inspecting configuration

To test your configuration, use

/usr/local/sbin/sshd -t

To see the resulting configuration, use

/usr/local/sbin/sshd -T

To check on the installations cryptographic capabilities, use ssh's -Q option

$ /usr/local/bin/ssh -Q help
cipher
cipher-auth
compression
kex
key
key-cert
key-plain
key-sig
mac
protocol-version
sig

To list the supported ciphers, keys and key-exchange methods, use:

$ /usr/local/bin/ssh -Q cipher
aes128-ctr
aes192-ctr
aes256-ctr
chacha20-poly1305@openssh.com
$ ssh -Q key
ssh-ed25519
ssh-ed25519-cert-v01@openssh.com
sk-ssh-ed25519@openssh.com
sk-ssh-ed25519-cert-v01@openssh.com
ssh-mldsa44-ed25519
ssh-mldsa44-ed25519-cert
$ ssh -Q kex
curve25519-sha256
curve25519-sha256@libssh.org
sntrup761x25519-sha512
sntrup761x25519-sha512@openssh.com
mlkem768x25519-sha256

For a very strict, PQC config only, add to /usr/local/etc/ssh/sshd_config

Ciphers chacha20-poly1305@openssh.com,aes256-ctr
Macs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha2-512
KexAlgorithms mlkem768x25519-sha256,sntrup761x25519-sha512,sntrup761x25519-sha512@openssh.com
CASignatureAlgorithms ssh-mldsa44-ed25519
HostbasedAcceptedAlgorithms ssh-mldsa44-ed25519-cert,ssh-mldsa44-ed25519
HostKeyAlgorithms ssh-mldsa44-ed25519-cert,ssh-mldsa44-ed25519
PubkeyAcceptedAlgorithms ssh-mldsa44-ed25519-cert,ssh-mldsa44-ed25519

Warning

This will allow only the latest version of OpenSSH to connect to your server. You better make sure all your clients are also updated with the latest OpenSSH!

A nice side-effect? My daily security log has become a lot shorter: the script-kiddies don't know how to do mldsa44-ed25519... yet.

For something less strict, add the ed25519 values back to the corresponding configuration items. Anything not ancient will be able to connect just fine.