在Linux中使用自定义规则在多个端口上运行的SSH服务 [英] SSH service running on multiple ports with custom rules in Linux

查看:70
本文介绍了在Linux中使用自定义规则在多个端口上运行的SSH服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置服务器,并在多个端口(例如端口22和5522)上运行SSH服务,并且这些端口应具有一组不同的规则,即:我们为端口22添加的规则不应冲突遵循端口5522的规则.

I was working on setting up a server with SSH service running on multiple ports like say, port 22, and 5522 and these port should be having a different set of rules, ie: The rules we added for port 22 should not conflict with the rules for port 5522.

推荐答案

最初,可以通过将以下行添加到/etc/ssh/sshd_config 来使SSH服务侦听多个端口.

Initially, the SSH service can be made to listen to multiple ports by adding the following line to /etc/ssh/sshd_config.

Port 22
Port 5522

在这种情况下,您不能为不同的端口定义不同的规则.

In this scenario, you cannot define different rules for different ports.

我可以找到的解决方案之一是创建一个新服务以在端口5522上运行SSH服务,然后将该服务作为守护程序运行.

One of the solutions I could find is to create a new service to run SSH service on port 5522 and then running the service as daemon.

为此,请按照以下步骤操作:-

To do so please follow steps below:-

  1. 创建SSH服务的副本并命名,在这里我将副本命名为 sshd_config_custom

cp /etc/ssh/sshd_config /etc/ssh/sshd_config_custom

  1. 类似地,也创建服务的副本.

cp /lib/systemd/system/ssh.service /lib/systemd/system/sshd-custom.service

    使用任何方便的编辑器
  1. 打开/lib/systemd/system/sshd-custom.service 并进行更改
  1. open /lib/systemd/system/sshd-custom.service using any comfortable editor and change

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

保存并退出文件.

  1. 现在,您可以在/etc/ssh/sshd_config_custom 中添加行 Port 5522 ,并可以对此conf文件进行任何必要的更改.

  1. Now you can add the line Port 5522 in /etc/ssh/sshd_config_custom and can make any required changes to this conf file.

启用并启动我们创建的自定义服务.

Enable and start the custom service that we have created.

systemctl enable sshd-custom.service
systemctl start sshd-custom.service

让我知道是否还有其他建议

Let me know if there is any other suggestions

这篇关于在Linux中使用自定义规则在多个端口上运行的SSH服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆