跳到主要内容

SSH 密钥

iForge 使用应用级 SSH 实现 Git SSH 协议,与系统 sshd 独立。

工作原理

对比项应用级 SSH(iForge)原生 sshd
实现Go 内置 SSH server系统 sshd 进程
密钥存储数据库~/.ssh/authorized_keys
密钥管理Web UI 添加/删除手动编辑文件
公钥反查数据库查询用户文件系统查找
端口可配置(默认 2022)22

添加 SSH 密钥

  1. 生成密钥对(如尚未有):
ssh-keygen -t ed25519 -C "your-email@example.com"
  1. 复制公钥:
cat ~/.ssh/id_ed25519.pub
  1. 在 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 格式

端口配置

.envdocker-compose.yml 中设置:

IFORGE_SSH_ENABLED=true
IFORGE_SSH_PORT=2022 # 改为 22 则使用标准端口并启用 SCP-like 格式
端口冲突

如果宿主机已运行 sshd(端口 22),iForge SSH 不能同时使用 22 端口。 解决方案:

  1. 修改 sshd 端口,iForge 使用 22
  2. 或 iForge 使用非 22 端口(如 2022)

自定义克隆 URL 模板

管理员可在「系统设置」→「仓库设置」中自定义 SSH 克隆 URL 前缀模板:

  • 模板变量:{host}{port}
  • 示例:ssh://git@{host}:{port} → 自动生成完整克隆 URL
  • 端口 22 时自动转换为 SCP-like 格式