Files
terraform/ssh_keys/GITEA_SSH_SETUP.md

68 lines
1.9 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.
# Gitea 部署密钥配置指南
## 密钥信息
我们创建了使用 Ed25519 算法的 SSH 密钥对,这是目前最安全的 SSH 密钥算法之一。
## 密钥文件
- **私钥**: `gitea_deploy_key_ed25519`
- **公钥**: `gitea_deploy_key_ed25519.pub`
## 在 Gitea 中配置部署密钥
### 1. 添加部署密钥到 Gitea 仓库
1. 登录到你的 Gitea 实例
2. 导航到你的私有仓库
3. 点击 "Settings"(设置)
4. 在左侧菜单中选择 "Deploy Keys"(部署密钥)
5. 点击 "Add Key"(添加密钥)
6. 输入密钥标题,例如 "Deployment Key"
7. 将以下公钥内容粘贴到密钥字段中:
```
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB1Eiqridn8nvb0nzwX5qfkN7Z4U94vKtvCBf0pbDHvz gitea-deploy-key@private
```
8. 选择适当的权限(通常选择 "Read" 权限用于部署)
9. 点击 "Add Key"(添加密钥)
### 2. 配置服务器使用私钥
将私钥 `gitea_deploy_key_ed25519` 安装到你的部署服务器上:
1. 将私钥复制到服务器上的 `~/.ssh/` 目录
2. 设置正确的权限:
```bash
chmod 600 ~/.ssh/gitea_deploy_key_ed25519
```
3. 配置 SSH 客户端使用此密钥(在 `~/.ssh/config` 中):
```
Host your-gitea-host.com
IdentityFile ~/.ssh/gitea_deploy_key_ed25519
User git
```
### 3. 在 CI/CD 中使用
如果你在 CI/CD 系统中使用此密钥:
1. 将私钥内容作为密钥存储在 CI/CD 系统中
2. 在构建脚本中创建临时 SSH 配置:
```bash
mkdir -p ~/.ssh
echo "$GITEA_DEPLOY_KEY" > ~/.ssh/gitea_deploy_key_ed25519
chmod 600 ~/.ssh/gitea_deploy_key_ed25519
```
## 安全注意事项
- 保护好私钥文件,不要将其提交到代码仓库
- 定期轮换部署密钥建议每6-12个月
- 使用最小权限原则,只为密钥分配必要的访问权限
- 监控密钥的使用情况
## 备用密钥
我们也保留了 ECDSA 密钥作为备用选项,但建议优先使用 Ed25519 密钥。