修改ssh远程默认端口,ssh默认端口


1. 修改ssh配置文件

[root@distzabbix ~]# vim /etc/ssh/sshd_config

找到第17行附近#Port 22 将#注释去掉,再新加一行Port 4522

 15 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
 16 #
 17 Port 22
 18 Port 4522
 19 #AddressFamily any
 20 #ListenAddress 0.0.0.0
 21 #ListenAddress ::
 22
 23 # The default requires explicit activation of protocol 1
 24 #Protocol 2
 25
 26 # HostKey for protocol version 1
 27 #HostKey /etc/ssh/ssh_host_key

保存修改退出

2. 重启ssh服务

CentOS6 : /etc/init.d/sshd restart
CentOS7 : systemctl resatrt sshd

3.开放防火墙端口
iptables -I INPUT -p tcp --dport 4587 -j ACCEPT
service iptables save
4. 新建窗口测试连接

新开窗口是为了测试4587端口是否可以正常连接服务器,防止在修改conf的过程中,万一出现掉线断网误操作等未知情况时候,还能通过另外一个端口连接上去调试以免发生连接不上必须派人去机房,导致问题更加复杂麻烦。

如果成功则将上面ssh配置文件中Port 22删除

相关内容