Files
Hugo/content/blog/vps-basics.md
T

89 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "VPS 新手入门:从购买到上线一个网站"
date: 2026-05-12T19:00:00+08:00
draft: false
poet: |
路漫漫其修远兮,
吾将上下而求索。
——屈原,中国,约前340–前278
description: "买了一台云服务器之后怎么让它跑起来。从 SSH 登录、创建普通用户、配置密钥认证、设置 ufw 防火墙到用 Nginx 部署静态网站,一套完整的新手流程。"
tags:
- Linux
- VPS
- 教程
---
买了一台云服务器之后,怎么让它真正跑起来?这篇文章记录基本的 VPS 初始化和安全配置流程。
## 购买后的第一件事
拿到服务器 IP 和 root 密码后:
### 1. SSH 登录
```bash
ssh root@你的服务器IP
```
第一次登录会提示确认主机指纹,输入 `yes` 即可。
### 2. 创建普通用户
root 权限太大,日常操作应该用普通用户:
```bash
adduser 用户名
usermod -aG sudo 用户名
```
### 3. 配置 SSH 密钥登录
```bash
# 在本地机器上生成密钥
ssh-keygen -t ed25519
# 把公钥传到服务器
ssh-copy-id 用户名@服务器IP
```
然后编辑 `/etc/ssh/sshd_config`,关闭密码登录:
```
PasswordAuthentication no
```
### 4. 防火墙配置
用 ufw 简单配置:
```bash
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
```
### 5. 安装必要的软件
```bash
apt update && apt upgrade -y
apt install -y nginx curl wget git
```
## 部署静态网站
最简单的方式是用 Nginx:
1. 把构建好的静态文件放到 `/var/www/html` 或自定义目录
2. 配置 Nginx 站点文件指向该目录
3. 运行 `nginx -t && systemctl reload nginx`
## 安全底线
- 不要用 root 直接操作日常任务
- 关闭 SSH 密码登录
- 定期更新系统包
- 非必要不开放额外端口
服务器就像一间屋子,基础装修做好才能住得安心。