前言
我们现在为了防止SSH被爆破
我们还是修改一下Linux的SSH端口
备份 SSH 配置文件
1
| sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
|
修改 SSH 配置文件
- 打开我们的
SSH配置文件
1
| sudo vim /etc/ssh/sshd_config
|
- 添加我们想设置的端口
1 2 3 4 5 6 7 8
| # 取消文件的注释 - #Port 22
# 测试完成记得删除 + Port 22
# 修改为新的端口 + Port <SSH_New_Port>
|
禁用 root 远程登录
1 2 3 4 5
| # 删除 Root 远程登录 - PermitRootLogin yes
# 禁用 Root 远程登录 + PermitRootLogin no
|
重启 SSH 服务
1 2 3 4
| sudo systemctl restart sshd
sudo /etc/init.d/sshd restart
|
防火墙放行规则
ufw 添加 SSH 新端口规则
1
| sudo ufw allow <SSH_New_Port>
|
iptables 添加 SSH 新端口规则
1
| sudo iptables -A INPUT -p tcp --dport <SSH_New_Port> -j ACCEPT
|
firewalld 添加 SSH 新端口规则
1 2 3 4
| sudo firewall-cmd --permanent --zone=public --add-port=<SSH_New_Port>/tcp
firewall-cmd --reload
|
参考 & 引用
https://www.vpser.net/security/centos-debian-ubuntu-linux-change-ssh-port.html
https://blog.csdn.net/hml111666/article/details/123422039