With the default configuration of openssh-server and systemd, sshd will complain and crash when multiple connections are made and terminated in a quick succession, e.g. with `ssh-keyscan`. It results in the following errors in /var/log/auth.log:
```
Nov 22 20:53:34 {host} sshd[14567]: Unable to negotiate with {client} port 41460: no matching host key type found. Their offer: <email address hidden> [preauth]
Nov 22 20:53:34 {host} sshd[14570]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
Nov 22 20:53:34 {host} sshd[14569]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
Nov 22 20:53:34 {host} sshd[14568]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
Nov 22 20:53:34 {host} sshd[14566]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
Nov 22 20:53:47 {host} sshd[14584]: Connection closed by {client} port 59312 [preauth]
Nov 22 20:53:47 {host} sshd[14586]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
Nov 22 20:53:48 {host} sshd[14585]: fatal: chroot("/run/sshd"): No such file or directory [preauth]
```
The error is most likely caused by a race condition on removing /run/sshd, which is easily reproducible by ssh-keyscan.
I noticed that depeding on client, I'd sometimes miss all keys, sometimes get one, sometimes more.
Modifying the following files (they should me marked as modified in the bug report) seems to solve the issue, at least temporarily:
/usr/lib/systemd/system/ssh.service
/usr/lib/systemd/system/ssh@.service
In both cases, I added `RuntimeDirectoryPreserve=yes` to the `[Service]` section, after `RuntimeDirectory=sshd`.
This is the same solution mentioned in the Debian bug, although their bug report doesn't mention which service files are affected.
This doesn't seem to be a proper long-term solution though, as it seems apt doesn't respect configuration files in /usr (or they are unlisted somewhere),
because after upgrading system just before filing this bug report, the files got overwritten and reverted to their original form.
I only got asked about the /etc/ssh/sshd_config, which I have chosen to keep.
This is mostly the same issue as https:/ /bugs.debian. org/cgi- bin/bugreport. cgi?bug= 934663.
With the default configuration of openssh-server and systemd, sshd will complain and crash when multiple connections are made and terminated in a quick succession, e.g. with `ssh-keyscan`. It results in the following errors in /var/log/auth.log:
``` "/run/sshd" ): No such file or directory [preauth] "/run/sshd" ): No such file or directory [preauth] "/run/sshd" ): No such file or directory [preauth] "/run/sshd" ): No such file or directory [preauth] "/run/sshd" ): No such file or directory [preauth] "/run/sshd" ): No such file or directory [preauth]
Nov 22 20:53:34 {host} sshd[14567]: Unable to negotiate with {client} port 41460: no matching host key type found. Their offer: <email address hidden> [preauth]
Nov 22 20:53:34 {host} sshd[14570]: fatal: chroot(
Nov 22 20:53:34 {host} sshd[14569]: fatal: chroot(
Nov 22 20:53:34 {host} sshd[14568]: fatal: chroot(
Nov 22 20:53:34 {host} sshd[14566]: fatal: chroot(
Nov 22 20:53:47 {host} sshd[14584]: Connection closed by {client} port 59312 [preauth]
Nov 22 20:53:47 {host} sshd[14586]: fatal: chroot(
Nov 22 20:53:48 {host} sshd[14585]: fatal: chroot(
```
as well as e.g. missing responses in ssh-keyscan:
``` OpenSSH_ 8.2p1 Ubuntu-4ubuntu0.1 sha256, <email address hidden> ,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 ,aes128- ctr,aes192- ctr,aes256- ctr,<email address hidden>,<email address hidden> ,aes128- ctr,aes192- ctr,aes256- ctr,<email address hidden>,<email address hidden> ,hmac-sha2- 256,hmac- sha2-512, hmac-sha1 ,hmac-sha2- 256,hmac- sha2-512, hmac-sha1 sha256, <email address hidden> ,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 512,rsa- sha2-256, ssh-rsa, ecdsa-sha2- nistp256, ssh-ed25519 ,aes128- ctr,aes192- ctr,aes256- ctr,<email address hidden>,<email address hidden> ,aes128- ctr,aes192- ctr,aes256- ctr,<email address hidden>,<email address hidden> ,hmac-sha2- 256,hmac- sha2-512, hmac-sha1 ,hmac-sha2- 256,hmac- sha2-512, hmac-sha1 OpenSSH_ 8.2p1 Ubuntu-4ubuntu0.1 OpenSSH_ 8.2p1 Ubuntu-4ubuntu0.1 OpenSSH_ 8.2p1 Ubuntu-4ubuntu0.1 OpenSSH_ 8.2p1 Ubuntu-4ubuntu0.1
$ ssh-keyscan -vvv {host}
debug2: fd 3 setting O_NONBLOCK
debug3: conalloc: oname {host} kt 2
debug2: fd 4 setting O_NONBLOCK
debug3: conalloc: oname {host} kt 4
debug2: fd 5 setting O_NONBLOCK
debug3: conalloc: oname {host} kt 8
debug2: fd 6 setting O_NONBLOCK
debug3: conalloc: oname {host} kt 32
debug2: fd 7 setting O_NONBLOCK
debug3: conalloc: oname {host} kt 64
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
# {host}:22 SSH-2.0-
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-
debug2: host key algorithms: <email address hidden>
debug2: ciphers ctos: <email address hidden>
debug2: ciphers stoc: <email address hidden>
debug2: MACs ctos: <email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>
debug2: MACs stoc: <email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>
debug2: compression ctos: none,<email address hidden>
debug2: compression stoc: none,<email address hidden>
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-
debug2: host key algorithms: rsa-sha2-
debug2: ciphers ctos: <email address hidden>
debug2: ciphers stoc: <email address hidden>
debug2: MACs ctos: <email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>
debug2: MACs stoc: <email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>,<email address hidden>
debug2: compression ctos: none,<email address hidden>
debug2: compression stoc: none,<email address hidden>
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: (no match)
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
# {host}:22 SSH-2.0-
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
# {host}:22 SSH-2.0-
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
# {host}:22 SSH-2.0-
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
# {host}:22 SSH-2.0-
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
```
The error is most likely caused by a race condition on removing /run/sshd, which is easily reproducible by ssh-keyscan.
I noticed that depeding on client, I'd sometimes miss all keys, sometimes get one, sometimes more.
Modifying the following files (they should me marked as modified in the bug report) seems to solve the issue, at least temporarily: systemd/ system/ ssh.service systemd/ system/ ssh@.service ryPreserve= yes` to the `[Service]` section, after `RuntimeDirecto ry=sshd` .
/usr/lib/
/usr/lib/
In both cases, I added `RuntimeDirecto
This is the same solution mentioned in the Debian bug, although their bug report doesn't mention which service files are affected.
This doesn't seem to be a proper long-term solution though, as it seems apt doesn't respect configuration files in /usr (or they are unlisted somewhere), sshd_config, which I have chosen to keep.
because after upgrading system just before filing this bug report, the files got overwritten and reverted to their original form.
I only got asked about the /etc/ssh/
ProblemType: Bug system/ ssh.service lib/systemd/ system/ ssh@.service] ature: Ubuntu 5.4.0-54.60-generic 5.4.65 0ubuntu27. 12 esult: skip
DistroRelease: Ubuntu 20.04
Package: openssh-server 1:8.2p1-4ubuntu0.1 [modified: lib/systemd/
ProcVersionSign
Uname: Linux 5.4.0-54-generic x86_64
ApportVersion: 2.20.11-
Architecture: amd64
CasperMD5CheckR
Date: Mon Nov 23 15:09:32 2020
SourcePackage: openssh
UpgradeStatus: No upgrade log present (probably fresh install)