更新 开发指南 1 SSH密钥配置

2026-04-14 02:07:42 +00:00
parent d5fe3b3c82
commit 80171575a6
@@ -1,72 +1,75 @@
# SSH 密钥配置 # SSH 密钥配置
本文介绍如何创建 SSH 公私钥对并添加到 Gitea。 本文介绍如何创建 SSH 公私钥对并添加到 Gitea。
## 1. 创建 SSH 公私钥对 ## 1. 创建 SSH 公私钥对
如果没有现成的 SSH 密钥对,需要先生成一对。 如果没有现成的 SSH 密钥对,需要先生成一对。
### 生成命令 ### 生成命令
```bash ```bash
ssh-keygen -t ed25519 -C "your_email@example.com" ssh-keygen -t ed25519 -C "your_email@example.com"
``` ```
**参数说明:** **参数说明:**
- `-t ed25519`:使用 Ed25519 算法(推荐,比 RSA 更安全、更短) - `-t ed25519`:使用 Ed25519 算法(推荐,比 RSA 更安全、更短)
- `-C "your_email@example.com"`:注释,通常填你的邮箱,便于识别 - `-C "your_email@example.com"`:注释,通常填你的邮箱,便于识别
### 交互提示 ### 交互提示
``` ```
Generating public/private ed25519 key pair. Generating public/private ed25519 key pair.
Enter file in which to save key (/home/you/.ssh/id_ed25519): # 直接回车使用默认路径 Enter file in which to save key (/home/you/.ssh/id_ed25519): # 直接回车使用默认路径
Enter passphrase (empty for no passphrase): # 输入密码短语,建议设置,若不设置则直接回车 Enter passphrase (empty for no passphrase): # 输入密码短语,建议设置,若不设置则直接回车
Enter same passphrase again: # 确认密码短语,若不设置则直接回车 Enter same passphrase again: # 确认密码短语,若不设置则直接回车
``` ```
> **注意**:密码短语是你对私钥的额外保护,即使他人拿到私钥文件,没有密码也无法使用。请妥善保管,不要遗忘。 > **注意**:密码短语是你对私钥的额外保护,即使他人拿到私钥文件,没有密码也无法使用。请妥善保管,不要遗忘。
### 生成的文件 ### 生成的文件
| 文件 | 说明 | | 文件 | 说明 |
|------|------| |------|------|
| `~/.ssh/id_ed25519` | 私钥(**不要泄露**) | | `~/.ssh/id_ed25519` | 私钥(**不要泄露**) |
| `~/.ssh/id_ed25519.pub` | 公钥(需要填到 Gitea) | | `~/.ssh/id_ed25519.pub` | 公钥(需要填到 Gitea) |
### 确认文件存在 ### 确认文件存在
```bash ```bash
ls -la ~/.ssh/id_ed25519* ls -la ~/.ssh/id_ed25519*
``` ```
--- ---
## 2. 在 Gitea 上添加公钥 ## 2. 在 Gitea 上添加公钥
### 步骤 ### 步骤
1. **获取公钥内容** 1. **获取公钥内容**
```bash ```bash
cat ~/.ssh/id_ed25519.pub cat ~/.ssh/id_ed25519.pub
``` ```
输出类似于: 输出类似于:
``` ```
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBLABELOCATED/ahKwj98dsfsaf+ASDNo7your_email@example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBLABELOCATED/ahKwj98dsfsaf+ASDNo7your_email@example.com
``` ```
2. **登录 Gitea** 2. **登录 Gitea**
打开团队 Gitea 地址(如 `https://gitea.your-team.com`),登录你的账号。 打开团队 Gitea 地址(如 `https://gitea.your-team.com`),登录你的账号。
3. **添加公钥** 3. **添加公钥**
- 点击右上角头像 → **设置(Settings)** - 点击右上角头像 → **设置(Settings)**
- 左侧菜单找到 **SSH 密钥(SSH Keys)** - 左侧菜单找到 **SSH 密钥(SSH Keys)**
- 点击 **添加密钥(Add Key)** - 点击 **添加密钥(Add Key)**
- 填写: - 填写:
- **标题(Title)**:给密钥起个名字,如 `我的笔记本` 或 `Desktop-PC` - **标题(Title)**:给密钥起个名字,如 `我的笔记本` 或 `Desktop-PC`
- **密钥(Key)**:粘贴上一步 `cat` 输出的完整内容 - **密钥(Key)**:粘贴上一步 `cat` 输出的完整内容
- 点击 **添加(Add Key)** - 点击 **添加(Add Key)**
- [开发指南-2-连接验证](./%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97-2-%E8%BF%9E%E6%8E%A5%E9%AA%8C%E8%AF%81)