我在 Raspberry Pi 4 上使用 Debian 11(图片在这里找到)。sshd 已正确配置(我只编辑了 /etc/ssh/sshd_config,其余部分完全来自系统安装)并且在我手动启动时可以正常工作。但是它不会在启动时由 systemd 自动启动。sudo systemctl status sshd返回:
● 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)
journalctl 的输出中没有与 ssh 相关的内容。
这是/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
文件sshd_not_to_be_run不存在。network.target处于活动状态。我还安装了 auditd 只是为了进行故障排除,它自动成功启动,但重启后 ssh.service 仍然死机。
我没有主意了……
更新:
我刚刚发现每次连接需求都会产生一个 sshd 进程。它由 systemd 自己管理,当一些外国计算机尝试连接到我的时,它清楚地打印在日志中:
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>
这就像 sshd 的并行安装存在默认配置。如果不手动启动 sshd.service,我自己的配置(例如要使用的特定端口号)将无法工作。但是我可以使用默认端口成功连接到那个影子 sshd,并且systemctl status sshd仍然报告一个死服务......
情况变得令人毛骨悚然,我现在只需两根手指即可擦除 SD 卡并安装另一个预配置较少的发行版的映像。