![将 sshd 端口更改为 2222 仍然只接受端口 22 ubuntu 23.04](https://linux22.com/image/788590/%E5%B0%86%20sshd%20%E7%AB%AF%E5%8F%A3%E6%9B%B4%E6%94%B9%E4%B8%BA%202222%20%E4%BB%8D%E7%84%B6%E5%8F%AA%E6%8E%A5%E5%8F%97%E7%AB%AF%E5%8F%A3%2022%20ubuntu%2023.04%20.png)
答案1
简而言之,sshd 由 Systemd 控制。这在三行注释中概述了多于您的 Port 声明。阅读配置文件中的注释通常很有用,尤其是当事情没有按您预期的方式进行时。
如果您阅读建议的文件,它将包含以下代码片段:
The provided ssh.socket unit file sets ListenStream=22. If you need to have
it listen on a different address or port, then you will need to do this as
follows (modifying ListenStream to match your requirements):
mkdir -p /etc/systemd/system/ssh.socket.d
cat >/etc/systemd/system/ssh.socket.d/listen.conf <<EOF
[Socket]
ListenStream=2222
EOF
systemctl daemon-reload
See systemd.socket(5) for details.
我或许会建议这样做。我还强烈建议实际阅读文档。