1. Modify the remote port
Open the remote port configuration file:
vim /etc/ssh/sshd_config
Modify Port:
找到 #Port 22 这一行 将#删掉 系统默认22为远程端口。将22修改为自己想要的端口号即可
If it has been modified before, you can confirm the current port number by viewing all released ports.
firewall-cmd --zone=public --list-ports
Restart and refresh configuration files
#重启命令:
systemctl restart sshd.service
#如果不成功,可尝试以下两个命令
systemctl restart sshd
/etc/init.d/sshd restart
Note that an error may be reported when restarting the service. Since Centos comes with selinux, similar to 360 Security Guard, some modifications to the system configuration will be made, and some security services will be intercepted.
注意:禁用selinux
重启时可能会报:
Job for sshd.service failed because the control process exited with error code.
See "systemctl status sshd.service" and "journalctl -xe" for details.的错误,
可以根据提示"systemctl status sshd.service"查看。
这里是因为SElinux启用了。需要禁用selinux
2. Disable Selinux
Reason for disabling
在centos6中将远程端口添加到防火墙上之后基本已经可以正常远程了。
但是centos7中还有一个selinux的软件。类似于360的存,还是会拦截远程。需要关闭selinux
Enter the selinux configuration file
vi /etc/selinux/config
Modify the corresponding configuration
将 SELINUX=enforcing 修改为 SELINUX=disabled
按“Esc”退出编辑模式,输入:wq 保存修改,并退出
Text editing commands explained
#注:进入配置文件后,按 i 代表进入编辑模式,
刚进入时默认为命令行模式,可通过输入英文冒号后,输入相应的命令,进行对文本的增删改查
w 代表写入
q 代表退出
q!代表强制退出
详细命令可搜索vi/vim 命令详解
The settings will take effect after restarting the system.
3. Add the remote port to the firewall and allow it to pass
Add port to firewall
#使用指令:
firewall-cmd --zone=public --add-port=80/tcp --permanent
#其中80是你需要添加的远程端口号。
#添加成功之后,系统会提示;success 表示添加成功。
Update firewall information:
#使用指令:
firewall-cmd --reload
#提示 success 表示更新成功。
Restart the firewall:
systemctl restart firewalld.service
4. Check whether the port is modified successfully
windows local view
使用 ping IP 端口 或 tcping IP 端口
如 ping 123.123.123.123 12345 或 tcping 123.123.123.123 12345
Use the remote login tool putty to enter the corresponding account number and password
Check the firewall allowed ports
firewall-cmd--list-all