I’m using Debian 11 on a Raspberry Pi 4 (image found here). sshd is properly configured (I only edited /etc/ssh/sshd_config, the rest is completely fresh from system installation) and works correctly when I start it manually. However it doesn’t start automatically by systemd at boot. sudo systemctl status sshd returns this:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:sshd(8)
man:sshd_config(5)
There is nothing related to ssh in journalctl’s output.
This is the content of /lib/systemd/system/ssh.service:
[Unit]
Description=OpenBSD Secure Shell server
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target auditd.service
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
[Service]
EnvironmentFile=-/etc/default/ssh
ExecStartPre=/usr/sbin/sshd -t
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/usr/sbin/sshd -t
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartPreventExitStatus=255
Type=notify
RuntimeDirectory=sshd
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
Alias=sshd.service
The file sshd_not_to_be_run does not exist. network.target is active. I also installed auditd just for troubleshoot and it successfully starts automatically, but ssh.service is still dead after reboot.
I run out of ideas…
UPDATE:
I just discovered that a sshd process spawns on every connection demand. It is managed by systemd itself and it’s clearly printed in the journal when some foreign computers try to connect to mine:
oct. 30 13:09:30 RaspServeur systemd[1]: Started OpenBSD Secure Shell server per-connection daemon (117.68.2.55:45784).
░░ Subject: L'unité (unit) [email protected]:22-117.68.2.55:45784.service a terminé son démarrage
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ L'unité (unit) [email protected]:22-117.68.2.55:45784.service a terminé son démarrage, avec le résultat done.
oct. 30 13:09:30 RaspServeur audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='[email protected]:22-117.68.2.55:45784 comm="systemd" exe="/usr/lib/systemd/systemd" ho>
oct. 30 13:09:33 RaspServeur sshd[1861]: error: kex_exchange_identification: Connection closed by remote host
oct. 30 13:09:33 RaspServeur sshd[1861]: Connection closed by 117.68.2.55 port 45784
oct. 30 13:09:33 RaspServeur systemd[1]: [email protected]:22-117.68.2.55:45784.service: Succeeded.
░░ Subject: Unit succeeded
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ The unit [email protected]:22-117.68.2.55:45784.service has successfully entered the 'dead' state.
oct. 30 13:09:33 RaspServeur audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='[email protected]:22-117.68.2.55:45784 comm="systemd" exe="/usr/lib/systemd/systemd" hos>
It’s like a parallel installation of sshd exists with a default configuration. My own configuration with settings like a specific port number to use can’t work without starting manually the sshd.service. But I can successfully connect to that shadow sshd with default port, and systemctl status sshd still reports a dead service…
The situation becomes creepy, I’m now two fingers away to erase the SD card and install an image of another distribution with less pre-configuration.
raspi-config
command? Take a look at the following article. learn.adafruit.com/adafruits-raspberry-pi-lesson-6-using-ssh/…