## 前言
每次新买 VPS 后都要做一套初始配置,记录下来方便以后复用。
## 基础环境
系统选用 Ubuntu 20.04 LTS,SSH 登录后第一件事:
```bash
apt update && apt upgrade -y
apt install -y curl wget git vim ufw
```
## 用户与安全
```bash
# 创建普通用户
adduser deploy
usermod -aG sudo deploy
# SSH 配置
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd
```
## 防火墙
```bash
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
```
## 安装 Nginx
```bash
apt install -y nginx
systemctl enable nginx
systemctl start nginx
```
## 总结
以上是最基本的 VPS 安全配置流程,后续再根据实际需求安装数据库、Node.js 等环境。