3
配置 Git SSH 与 Gitea 集成指南
谭梦宁 edited this page 2026-05-06 19:43:06 +08:00
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.

生成 SSH 密钥对

在本地计算机上打开终端(Linux/macOS)或命令提示符/PowerShell(Windows),执行以下命令生成新的 SSH 密钥:

ssh-keygen -t ed25519 -C "your_email@example.com"
  • -t ed25519 指定使用 Ed25519 加密算法(推荐,安全性高)

  • -C 后面添加注释,通常是你的邮箱地址,用于标识该密钥

    按提示选择保存路径(默认为 ~/.ssh/id_ed25519)并设置可选的密码。完成后会生成两个文件:

  • 私钥:id_ed25519(请勿泄露)

  • 公钥:id_ed25519.pub(用于上传到 Gitea

    提示:如果你使用的是较老系统不支持 Ed25519,可以改用 ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

将公钥添加到 Gitea 账户

  1. 登录你的 Gitea 实例:http://175.27.253.162:3000/
  2. 点击右上角用户头像 → Settings(设置)

图片描述

  1. 在左侧菜单中选择 SSH / GPG 密钥 → 管理 SSH 密钥
  2. 打开公钥文件(如 ~/.ssh/id_ed25519.pub),复制其全部内容
    cat ~/.ssh/id_ed25519.pub
    
  3. 在 Gitea 的 密钥内容文本框中粘贴公钥内容
  4. 密钥名称可填写设备名称
  5. 点击 添加密钥 完成添加

图片描述

图片描述

测试 SSH 连接

在终端运行以下命令测试是否能成功连接到 Gitea 服务器:

ssh -T ssh://git@175.27.253.162:222

首次连接时会提示确认主机指纹,请输入 yes 继续。如果配置正确,应看到类似以下输出:

Hi username! You've successfully authenticated, but Gitea does not provide shell access.

这表示 SSH 认证已生效。 图片描述