1.8 KiB
1.8 KiB
SSH 密钥配置指南
✅ SSH 密钥已生成
您的 SSH 密钥已保存在:
- 私钥:
/c/Users/Administrator/.ssh/id_rsa - 公钥:
/c/Users/Administrator/.ssh/id_rsa.pub
下一步:将公钥添加到 Gerrit
步骤 1:查看公钥内容
在 Git Bash 中执行:
cat ~/.ssh/id_rsa.pub
或者:
type ~/.ssh/id_rsa.pub
步骤 2:复制公钥
复制输出的完整内容(从 ssh-rsa 开始到邮箱结束的整行),例如:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD... your_email@example.com
步骤 3:添加到 Gerrit
- 打开浏览器,访问:
http://101.43.95.130:8080/#/settings/ssh-keys - 粘贴公钥到 "SSH Public Keys" 页面的输入框
- 点击 "Add" 按钮保存
步骤 4:测试 SSH 连接
在 Git Bash 中执行:
ssh -p 29418 renjianbo@101.43.95.130 gerrit version
如果连接成功,会显示 Gerrit 版本信息。
步骤 5:使用 SSH 推送代码
cd /d/ttt/test-project
# 删除当前的 HTTP 远程仓库
git remote remove origin
# 添加 SSH 远程仓库
git remote add origin ssh://renjianbo@101.43.95.130:29418/test-project
# 查看远程仓库配置
git remote -v
# 推送代码
git push origin HEAD:refs/for/master
如果 SSH 连接失败
检查防火墙
确保服务器的 29418 端口已开放。
检查 SSH 服务
在服务器上检查 Gerrit SSH 服务是否运行:
cd /home/renjianbo/gerrit_install/review_site
bin/gerrit.sh status
查看 SSH 日志
cd /home/renjianbo/gerrit_install/review_site
tail -f logs/sshd_log
完成后的操作
SSH 配置完成后,您就可以:
- ✅ 使用 SSH 克隆项目
- ✅ 使用 SSH 推送代码
- ✅ 使用 SSH 执行 Gerrit 命令
SSH 方式比 HTTP 更可靠,推荐使用!