ubuntu24系统如何做好防御?
美国、香港服务器
ubuntu24系统如何做好防御?
04-21 来源:
一、基础必做(最关键)
1. 保持系统更新
bash
运行
sudo apt update && sudo apt upgrade -y
2. 配置 UFW 防火墙(严格模式)
bash
运行
sudo apt install ufw -y
# 默认拒绝所有入站,允许所有出站
sudo ufw default deny incoming
sudo ufw default allow outgoing
# 放行必要端口
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# 启用防火墙
sudo ufw enable
查看状态:
bash
运行
sudo ufw status verbose
3. 禁止 root 直接 SSH 登录
bash
运行
sudo nano /etc/ssh/sshd_config
修改:
plaintext
PermitRootLogin no
重启 SSH:
bash
运行
sudo systemctl restart sshd
4. 安装 fail2ban 防暴力破解
bash
运行
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
默认配置就足够防御 SSH 爆破。
二、进阶加固(强烈建议)
1. 修改 SSH 默认端口(防扫描)
bash
运行
sudo nano /etc/ssh/sshd_config
修改:
plaintext
Port 22345 # 10000~65535 之间随便写
防火墙放行新端口:
bash
运行
sudo ufw allow 22345/tcp
sudo ufw reload
sudo systemctl restart sshd
2. 只使用密钥登录,关闭密码登录
bash
运行
sudo nano /etc/ssh/sshd_config
设置:
plaintext
PasswordAuthentication no
ChallengeResponseAuthentication no
重启 SSH:
bash
运行
sudo systemctl restart sshd
3. 创建普通用户 + sudo 权限
bash
运行
sudo adduser myuser
sudo usermod -aG sudo myuser
以后只用这个用户登录,不用 root。
三、防木马、防挖矿(非常重要)
不运行任何来历不明的一键脚本
不使用破解版软件、破解版面板
MySQL、Redis、MongoDB 等不对外开放端口
定期检查:
bash
运行
ps aux # 看异常进程
top # 看 CPU 占用
crontab -l # 看异常定时任务
三二互联专业提供香港VPS,美国VPS主机,香港云服务器租用等业务香港美国到大陆CN2 GIA速度最快