DEV Community

lam duc
lam duc

Posted on

5 bước bảo mật cơ bản cho VPS Linux ngay sau khi nhận máy

Một VPS mới thường bị dò mật khẩu SSH chỉ vài phút sau khi có IP công khai. Dưới đây là 5 bước nên làm ngay trong 15 phút đầu tiên, áp dụng cho Ubuntu/Debian.

1. Cập nhật hệ thống

sudo apt update && sudo apt upgrade -y
Enter fullscreen mode Exit fullscreen mode

Bản vá bảo mật được phát hành liên tục; một máy chưa cập nhật là mục tiêu dễ nhất.

2. Tạo người dùng riêng, không dùng root hằng ngày

adduser deploy
usermod -aG sudo deploy
Enter fullscreen mode Exit fullscreen mode

3. Đăng nhập SSH bằng khoá, tắt mật khẩu

Trên máy của bạn: ssh-copy-id deploy@IP_VPS. Sau khi đăng nhập bằng khoá thành công, sửa /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
Enter fullscreen mode Exit fullscreen mode

rồi sudo systemctl reload ssh. Luôn giữ một phiên SSH đang mở trong lúc thử, để không tự khoá mình ở ngoài.

4. Bật tường lửa, chỉ mở cổng cần dùng

sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

5. Chặn dò mật khẩu và tự cập nhật bản vá

sudo apt install -y fail2ban unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Enter fullscreen mode Exit fullscreen mode

Năm bước này không thay cho sao lưu định kỳ và giám sát, nhưng đã chặn được phần lớn các cuộc tấn công tự động nhắm vào VPS mới.

Top comments (0)