在CentOS版本6.2(最终)的多个端口上运行SSHD

我正在运行CentOS版本6.2(最终)。

我想在端口22和1022上侦听sshd端口。

我将以下几行添加到/ etc / ssh / sshd_config中:

Port 22 Port 1022 

并重新启动sshd并closures了iptables,但是我无法连接到端口1022上的sshd。

即使我做了以下

 #Port 22 Port 1022 

sshd继续监听端口22,不监听端口1022.我尝试了除1022以外的其他端口值,但没有运气。

帮帮我!

如果你使用的是CentOS 5,你所描述的configuration确实有效,但是一个快速testing表明,CentOS 6上的sshd不会绑定到1023以下的任何端口,除了22以外 – 目前我找不到这个参考。 如果你想访问多个端口上的sshd,然后select一个> = 1024。


更新 – 这与SELinux有关。 当前策略不允许sshd绑定到1023以下的非标准端口(如实validation实)

 semanage port -l | grep 22 ssh_port_t tcp 22 

如果你想添加一个额外的端口<= 1023,你将不得不在SELinux中明确地允许它

 semanage port -a -t ssh_port_t -p tcp 1022 semanage port -l | grep 22 ssh_port_t tcp 1022, 22 

然后重新启动sshd

 netstat -tnlp tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 25376/sshd tcp 0 0 0.0.0.0:1022 0.0.0.0:* LISTEN 25376/sshd 

这基本上不推荐,但无论如何这是可以实现的。

 cp /etc/ssh/sshd_config /etc/ssh/sshd_config-another 

编辑sshd-config-another文件并分配不同的端口号和pid文件。

 Port 1022 PidFile /var/run/sshd-another.pid 

现在跑,

 ln -s /usr/sbin/sshd /usr/bin/sshd-another cp /etc/rc.d/init.d/sshd /etc/rc.d/init.d/sshd-another 

打开新的初始化脚本并相应地进行更改。

 # config: /etc/ssh/sshd_config-another # pidfile: /var/run/sshd-another.pid [ -f /etc/sysconfig/sshd-another ] && . /etc/sysconfig/sshd-another prog="sshd-another" SSHD=/usr/sbin/sshd-another PID_FILE=/var/run/sshd-another.pid 

创build/etc/sysconfig/sshd-second文件。

 OPTIONS="-f /etc/ssh/sshd_config-another" 

独立的PAMconfiguration。

 ln -s /etc/pam.d/sshd /etc/pam.d/sshd-another 

重新启动服务。

 service sshd restart service sshd-another restart 

chkconfig吧。

 chkconfig --add sshd-another chkconfig on sshd-another