网站搭建指南

选择合适的云服务器

安装git

安装操作

这里用Ubuntu来举例:

  • 安装
1
2
sudo apt update
sudo apt install -y git
  • 验证
1
git --version
  • 配置
1
2
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"
  • 查看配置
1
git config --list

连接github

  • 生成ssh密钥
1
ssh-keygen -t ed25519 -C "你的邮箱@example.com"
  • 一路回车生成
1
2
/home/ubuntu/.ssh/id_ed25519
/home/ubuntu/.ssh/id_ed25519.pub
  • 然后把公钥内容复制出来:
1
cat ~/.ssh/id_ed25519.pub

把公钥添加到GitHub

  1. 登录 GitHub

  2. 点击右上角头像 → SettingsSSH and GPG keys

  3. 点击 New SSH key

  • Title 随意写,比如 “My Ubuntu Server”。
  • Key type: SSH。
  • Key 内容粘贴刚刚复制的 id_ed25519.pub
  1. 保存。

连接测试

1
ssh -T [email protected]

第一次会显示:

1
Are you sure you want to continue connecting (yes/no/[fingerprint])?

输入yes并等待:

1
Hi yourname! You've successfully authenticated...

说明成功了

博客搭建

推荐目录结构

1
2
3
/var/www/
└── blog.example.com/
└── public/ ← 放生成的静态文件(index.html、css、img 等)

目录生成

1
sudo mkdir -p /var/www

文件克隆

1
2
sudo git clone [email protected]:你的用户名/你的博客仓库.git blog.example.com
sudo chown -R www-data:www-data blog.example.com