在CentOS6.*时代修改ssh端口非常简单,直接修改/etc/ssh/sshd_config文件后重启ssh服务就好了,不过在CentOS7绝大部分还要关闭SElinux或者防火墙放行端口,搜索引擎找到的经常不是很全面,所以自己记录下方便修改的时候参考和复制相关命令,免得每次都去找。文章在HostYun和80VPS两家的KVM主机上测试。

1.修改配置文件添加新的端口

[[email protected] ~]# vi /etc/ssh/sshd_config

找到#Port 22,去掉前面的#并新加一行Port xxxx(xxxx指新的端口),然后保存退出。

ssh_port01

2.防火墙放行端口

[[email protected] ~]# firewall-cmd --zone=public --add-port=2322/tcp --permanent
#2322指新的端口
[[email protected] ~]# firewall-cmd –reload

如果我们的防火墙是关闭状态,这一步可以忽略,不过还是开着吧。

3.关闭SElinux

[[email protected] ~]# vi /etc/selinux/config

ssh_port02

这里主要修改SELINUX=enforcing为SELINUX=disabled,完成后保存,重启。

***这一步也可以操作为向SELinux中添加ssh端口而不是直接关闭SELINUX,具体步骤命令如下。

[[email protected] ~]# yum provides semanage
#安装管理工具

[[email protected] ~]#yum -y install policycoreutils-python
#安装依赖包

[[email protected] ~]#semanage port -l | grep ssh
#查询ssh端口

[[email protected] ~]#semanage port -a -t ssh_port_t -p tcp 2322
#向SELinux中添加ssh端口

[[email protected] ~]#systemctl restart sshd.service
#重启sshd服务

标签: centos7修改ssh端口, centos7修改端口, centos修改ssh端口, ssh端口

window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":["mshare","kaixin001","tsina","tsohu","tqq","renren","qzone","weixin","bdysc","bdxc","tqf","tieba","douban","bdhome","sqq","thx"],"bdPic":"","bdStyle":"0","bdSize":"24"},"slide":{"type":"slide","bdImg":"2","bdPos":"left","bdTop":"100"},"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["tsina","tqq","tsohu","qzone","renren","weixin","mshare"]}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
postid
24433

发表评论