Bảo Mật VPS Linux: Hướng Dẫn Toàn Diện
Bảo mật VPS là việc không thể bỏ qua. Một server không được bảo mật đúng cách có thể bị xâm nhập trong vài phút sau khi đi online. Hướng dẫn này trình bày các bước thiết yếu để bảo mật VPS Linux của bạn trên AnubizHost, từ cơ bản đến nâng cao.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
Cứng Hóa SSH
SSH là cổng vào chính của server. Bảo mật SSH là bước đầu tiên và quan trọng nhất. Chỉnh sửa file cấu hình:
nano /etc/ssh/sshd_configThay đổi các dòng sau:
# Đổi port mặc định (22) sang port khác
Port 2222
# Tắt đăng nhập root bằng password
PermitRootLogin prohibit-password
# Chỉ cho phép xác thực bằng SSH key
PasswordAuthentication no
PubkeyAuthentication yes
# Giới hạn số lần thử đăng nhập
MaxAuthTries 3
LoginGraceTime 20Reload SSH: systemctl restart sshd
Tạo SSH key pair trên máy local và copy public key lên server trước khi tắt password auth.
Cài Đặt và Cấu Hình Fail2ban
Fail2ban tự động block IP có hành vi đáng ngờ (brute force, quá nhiều lần thử đăng nhập):
apt install -y fail2ban
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
nano /etc/fail2ban/jail.localCấu hình cơ bản:
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 3
[sshd]
enabled = true
port = 2222
logpath = /var/log/auth.logKhởi động Fail2ban:
systemctl enable fail2ban
systemctl start fail2banKiểm tra các IP đang bị ban: fail2ban-client status sshd
Cập Nhật Tự Động và Quản Lý Package
Cập nhật hệ thống thường xuyên là biện pháp bảo mật đơn giản nhưng hiệu quả nhất. Cài đặt unattended-upgrades:
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgradesCấu hình trong /etc/apt/apt.conf.d/50unattended-upgrades:
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::Remove-Unused-Dependencies "true";Loại bỏ software không cần thiết để giảm bề mặt tấn công:
apt autoremove --purge
apt list --installed | grep -v "lib"Giám Sát và Phát Hiện Xâm Nhập
Cài đặt Lynis để audit bảo mật định kỳ:
apt install -y lynis
lynis audit systemCài đặt rkhunter để kiểm tra rootkit:
apt install -y rkhunter
rkhunter --update
rkhunter --checkTheo dõi log đăng nhập thất bại:
grep "Failed password" /var/log/auth.log | tail -20
last -f /var/log/wtmp | head -20Thiết lập cảnh báo qua email khi có đăng nhập thành công từ IP lạ bằng cách thêm vào /etc/profile:
echo "Alert: SSH login from $(who am i | awk '{print $5}')" | mail -s "SSH Login Alert" [email protected]Related Services
Why Anubiz Host
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.