Files
gerrit/SSH密钥配置指南.md
2025-12-22 17:12:39 +08:00

97 lines
1.8 KiB
Markdown
Raw Permalink Blame History

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 密钥配置指南
## ✅ SSH 密钥已生成
您的 SSH 密钥已保存在:
- 私钥:`/c/Users/Administrator/.ssh/id_rsa`
- 公钥:`/c/Users/Administrator/.ssh/id_rsa.pub`
## 下一步:将公钥添加到 Gerrit
### 步骤 1查看公钥内容
在 Git Bash 中执行:
```bash
cat ~/.ssh/id_rsa.pub
```
或者:
```bash
type ~/.ssh/id_rsa.pub
```
### 步骤 2复制公钥
复制输出的完整内容(从 `ssh-rsa` 开始到邮箱结束的整行),例如:
```
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD... your_email@example.com
```
### 步骤 3添加到 Gerrit
1. **打开浏览器**,访问:`http://101.43.95.130:8080/#/settings/ssh-keys`
2. **粘贴公钥**到 "SSH Public Keys" 页面的输入框
3. **点击 "Add"** 按钮保存
### 步骤 4测试 SSH 连接
在 Git Bash 中执行:
```bash
ssh -p 29418 renjianbo@101.43.95.130 gerrit version
```
如果连接成功,会显示 Gerrit 版本信息。
### 步骤 5使用 SSH 推送代码
```bash
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 服务是否运行:
```bash
cd /home/renjianbo/gerrit_install/review_site
bin/gerrit.sh status
```
### 查看 SSH 日志
```bash
cd /home/renjianbo/gerrit_install/review_site
tail -f logs/sshd_log
```
## 完成后的操作
SSH 配置完成后,您就可以:
- ✅ 使用 SSH 克隆项目
- ✅ 使用 SSH 推送代码
- ✅ 使用 SSH 执行 Gerrit 命令
SSH 方式比 HTTP 更可靠,推荐使用!