commit 2aefa4ad5b6b04883d5fd15a6681b970b9d90cb7 Author: 谭梦宁 Date: Wed Nov 5 15:21:10 2025 +0800 添加 配置 Git SSH 与 Gitea 集成指南 diff --git a/%E9%85%8D%E7%BD%AE-Git-SSH-%E4%B8%8E-Gitea-%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97.md b/%E9%85%8D%E7%BD%AE-Git-SSH-%E4%B8%8E-Gitea-%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97.md new file mode 100644 index 0000000..ce371b8 --- /dev/null +++ b/%E9%85%8D%E7%BD%AE-Git-SSH-%E4%B8%8E-Gitea-%E9%9B%86%E6%88%90%E6%8C%87%E5%8D%97.md @@ -0,0 +1,39 @@ +# 生成 SSH 密钥对 +在本地计算机上打开终端(Linux/macOS)或命令提示符/PowerShell(Windows),执行以下命令生成新的 SSH 密钥: +```bash +ssh-keygen -t ed25519 -C "your_email@example.com" +``` +- -t ed25519 指定使用 Ed25519 加密算法(推荐,安全性高) +- -C 后面添加注释,通常是你的邮箱地址,用于标识该密钥 + +按提示选择保存路径(默认为 `~/.ssh/id_ed25519`)并设置可选的密码(passphrase)。完成后会生成两个文件: + +- 私钥: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(设置) +3. 在左侧菜单中选择 SSH / GPG 密钥 → 管理 SSH 密钥 +4. 打开公钥文件(如 ~/.ssh/id_ed25519.pub),复制其全部内容 + ```bash + cat ~/.ssh/id_ed25519.pub + ``` +5. 在 Gitea 的 密钥内容文本框中粘贴公钥内容 +6. 密钥名称可填写设备名称 +7. 点击 **添加密钥** 完成添加 + + +# 测试 SSH 连接 +在终端运行以下命令测试是否能成功连接到 Gitea 服务器: +```bash +ssh -T ssh://git@175.27.253.162:222 +``` +首次连接时会提示确认主机指纹,请输入` yes` 继续。如果配置正确,应看到类似以下输出: +```bash +Hi username! You've successfully authenticated, but Gitea does not provide shell access. +```` +这表示 SSH 认证已生效。