CentOS7修改默认ssh端口22
CentOS7修改默认ssh端口22
1.查看防火墙状态firewall-cmd --state或者systemctl status firewalld为running(centos默认是firewalld).如果不是running使用systemctl start firewalld 开启并设置开机自启systemctl enable firewalld;
2.查看firewall-cmd --list-ports已开放的端口(默认不开放任何端口);
3.自定义端口11111并开启 ;
firewall-cmd --permanent --zone=public --add-port=11111/tcp
4.重启防火墙firewall-cmd --reload;
5.修改配置文件etc/ssh/config,在第17行之后添加Port 11111,保存退出;
6.重启服务systemctl restart sshd.service;
7.使用xshell连接。若连接不上,请检查selinux状态是否为disabled /usr/sbin/sestatus -v ,不是修改文件vim /etc/selinux/config 将SELINUX=enforcing改为SELINUX=disabled(这种方式为永久性关闭,也可以安装semanage将ssh添加至规则)
8.重启机器 reboot即可;
遇到问题:设置完成之后依然连接不上
原因是:我使用的是阿里云专有网络,需要配置安全组