SSH 密钥
iForge 使用应用级 SSH 实现 Git SSH 协议,与系统 sshd 独立。
工作原理
| 对比项 | 应用级 SSH(iForge) | 原生 sshd |
|---|---|---|
| 实现 | Go 内置 SSH server | 系统 sshd 进程 |
| 密钥存储 | 数据库 | ~/.ssh/authorized_keys |
| 密钥管理 | Web UI 添加/删除 | 手动编辑文件 |
| 公钥反查 | 数据库查询用户 | 文件系统查找 |
| 端口 | 可配置(默认 2022) | 22 |
添加 SSH 密钥
- 生成密钥对(如尚未有):
ssh-keygen -t ed25519 -C "your-email@example.com"
- 复制公钥:
cat ~/.ssh/id_ed25519.pub
- 在 iForge 中添加:
- 进入「设置」→「SSH 密钥」
- 粘贴公钥,点击「添加」
使用 SSH 克隆
非标准端口(如 2022)
git clone ssh://git@your-host:2022/owner/repo.git
标准端口 22(SCP-like 格式)
当 SSH 端口配置为 22 时,克隆 URL 自动转换为简洁的 SCP-like 格式:
git clone git@your-host:owner/repo.git
自动转换规则
- 端口为 22 时:自动省略
ssh://前缀和端口号,转换为git@host:owner/repo.git - 端口非 22 时:保持
ssh://git@host:port/owner/repo.git格式
端口配置
在 .env 或 docker-compose.yml 中设置:
IFORGE_SSH_ENABLED=true
IFORGE_SSH_PORT=2022 # 改为 22 则使用标准端口并启用 SCP-like 格式
端口冲突
如果宿主机已运行 sshd(端口 22),iForge SSH 不能同时使用 22 端口。 解决方案:
- 修改 sshd 端口,iForge 使用 22
- 或 iForge 使用非 22 端口(如 2022)
自定义克隆 URL 模板
管理员可在「系统设置」→「仓库设置」中自定义 SSH 克隆 URL 前缀模板:
- 模板变量:
{host}、{port} - 示例:
ssh://git@{host}:{port}→ 自动生成完整克隆 URL - 端口 22 时自动转换为 SCP-like 格式