多个端口上的 SSH 服务 运行,自定义规则在 Linux
SSH service running on multiple ports with custom rules in Linux
我正致力于在多个端口(例如端口 22 和 5522)上设置具有 SSH 服务 运行 的服务器,这些端口应该具有一组不同的规则,即:我们添加的规则端口 22 不应与端口 5522 的规则冲突。
最初,可以通过将以下行添加到 /etc/ssh/sshd_config
.
来使 SSH 服务监听多个端口
Port 22
Port 5522
在这种情况下,您不能为不同的端口定义不同的规则。
我能找到的解决方案之一是在端口 5522 上为 运行 SSH 服务创建一个新服务,然后 运行将该服务作为守护进程。
为此,请按照以下步骤操作:-
- 创建SSH服务的副本并命名,这里我将副本命名为
sshd_config_custom
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_custom
- 同样,也创建服务的副本。
cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-custom.service
- 使用任何舒适的编辑器打开
/lib/systemd/system/sshd-custom.service
并更改
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
到
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f /etc/ssh/sshd_config_custom
和
Alias=sshd.service
到
Alias=sshd-custom.service
保存并退出文件。
现在您可以在 /etc/ssh/sshd_config_custom
中添加行 Port 5522
并且可以对该 conf 文件进行任何必要的更改。
启用并启动我们创建的自定义服务。
systemctl enable sshd-custom.service
systemctl start sshd-custom.service
如果有任何其他建议,请告诉我
我正致力于在多个端口(例如端口 22 和 5522)上设置具有 SSH 服务 运行 的服务器,这些端口应该具有一组不同的规则,即:我们添加的规则端口 22 不应与端口 5522 的规则冲突。
最初,可以通过将以下行添加到 /etc/ssh/sshd_config
.
Port 22
Port 5522
在这种情况下,您不能为不同的端口定义不同的规则。
我能找到的解决方案之一是在端口 5522 上为 运行 SSH 服务创建一个新服务,然后 运行将该服务作为守护进程。
为此,请按照以下步骤操作:-
- 创建SSH服务的副本并命名,这里我将副本命名为
sshd_config_custom
cp /etc/ssh/sshd_config /etc/ssh/sshd_config_custom
- 同样,也创建服务的副本。
cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-custom.service
- 使用任何舒适的编辑器打开
/lib/systemd/system/sshd-custom.service
并更改
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
到
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS -f /etc/ssh/sshd_config_custom
和
Alias=sshd.service
到
Alias=sshd-custom.service
保存并退出文件。
现在您可以在
/etc/ssh/sshd_config_custom
中添加行Port 5522
并且可以对该 conf 文件进行任何必要的更改。启用并启动我们创建的自定义服务。
systemctl enable sshd-custom.service
systemctl start sshd-custom.service
如果有任何其他建议,请告诉我