vi

Cài Đặt Linux VPS Từ Đầu: Hướng Dẫn Từng Bước

Khi nhận VPS mới, bạn có một server Linux trần với quyền root. Bước tiếp theo là thiết lập môi trường an toàn và ổn định trước khi triển khai ứng dụng. Hướng dẫn này dành cho người mới bắt đầu với VPS Linux, sử dụng Ubuntu 22.04 LTS - bản phân phối phổ biến nhất và được hỗ trợ tốt nhất.

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

Bước 1: Kết Nối SSH và Cập Nhật Hệ Thống

Sau khi nhận thông tin đăng nhập VPS, kết nối qua SSH từ terminal:

ssh root@IP_CUA_VPS

Nhập mật khẩu được cung cấp. Lần đầu đăng nhập, cập nhật toàn bộ phần mềm:

apt update
apt upgrade -y
apt autoremove -y

Quá trình này có thể mất vài phút. Sau khi hoàn thành, đặt hostname cho server:

hostnamectl set-hostname ten-server-cua-ban

Đặt timezone về múi giờ phù hợp:
timedatectl set-timezone Asia/Ho_Chi_Minh

Bước 2: Tạo User Thông Thường và SSH Key

Chạy mọi thứ bằng root là rủi ro bảo mật. Tạo user thông thường:

adduser ten_user_cua_ban
usermod -aG sudo ten_user_cua_ban

Tạo SSH key trên máy tính của bạn (không phải trên server):
ssh-keygen -t ed25519 -C "comment"

Copy public key lên server:
ssh-copy-id ten_user@IP_VPS

Hoặc thủ công, tạo thư mục .ssh và authorized_keys:
mkdir -p /home/ten_user/.ssh
echo "NOI_DUNG_PUBLIC_KEY_CUA_BAN" >> /home/ten_user/.ssh/authorized_keys
chmod 700 /home/ten_user/.ssh
chmod 600 /home/ten_user/.ssh/authorized_keys
chown -R ten_user:ten_user /home/ten_user/.ssh

Bước 3: Bảo Mật SSH và Firewall

Sửa cấu hình SSH để tắt đăng nhập bằng mật khẩu và đăng nhập root:

nano /etc/ssh/sshd_config

Tìm và sửa các dòng sau:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

Restart SSH (không ngắt kết nối hiện tại):
systemctl restart sshd

Mở terminal mới, kiểm tra có thể đăng nhập bằng key không trước khi đóng terminal cũ.

Cài và cấu hình firewall UFW:
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw enable

Thêm port khác khi cần (ví dụ HTTP/HTTPS):
ufw allow 80/tcp
ufw allow 443/tcp

Bước 4: Cài Đặt Công Cụ Cơ Bản

Một số công cụ hữu ích nên cài ngay từ đầu:

apt install -y
curl wget git vim htop
unzip net-tools
fail2ban ufw
tmux screen

Fail2ban tự động ban IP đăng nhập sai nhiều lần. Khởi động và enable:
systemctl enable fail2ban
systemctl start fail2ban

Tmux cho phép giữ session khi bị ngắt kết nối SSH. Rất hữu ích khi chạy lệnh dài:

tmux new -s session_name
# Chạy lệnh...
# Ctrl+B sau đó D để detach
tmux attach -t session_name # Quay lại session

Cài Docker nếu cần (nhiều ứng dụng hiện đại chạy qua container):
curl -fsSL https://get.docker.com | sh
usermod -aG docker ten_user_cua_ban

Why Anubiz Host

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

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.

Anubiz Chat AI

Online