新购 VPS 服务器初始化设置指南 Print

  • 46

购买一台新的 VPS 后,第一步就是对其进行初始化配置,以确保系统安全稳定运行。本文以 Ubuntu 22.04 LTS 为例,介绍标准初始化流程。

1. 通过 SSH 连接

ssh root@your_server_ip

2. 更新系统包

sudo apt update
sudo apt upgrade -y

3. 创建新用户

adduser username
usermod -aG sudo username

4. 配置 SSH 密钥登录

# 在本地生成密钥(如未有)
ssh-keygen -t ed25519 -C "your_email"
# 复制公钥到服务器
ssh-copy-id username@your_server_ip

5. 修改 SSH 配置

编辑 /etc/ssh/sshd_config

Port 2222
PermitRootLogin no
PasswordAuthentication no
AllowUsers username
sudo systemctl restart sshd

6. 配置防火墙

sudo ufw allow 2222/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

7. 设置时区与时间同步

sudo timedatectl set-timezone Asia/Shanghai
sudo apt install ntp
sudo systemctl enable ntp

8. 自动安全更新

sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades

完成以上步骤后,服务器就已经具备了基本的安全防护和稳定的运行环境。


Was this answer helpful?

« Back