鏇存柊鏂囨。
This commit is contained in:
133
docs/gerrit/生成并配置SSH密钥、克隆仓库.md
Normal file
133
docs/gerrit/生成并配置SSH密钥、克隆仓库.md
Normal file
@@ -0,0 +1,133 @@
|
||||
你的操作指南非常详细和准确!我帮你重新整理了一个更清晰的流程,并修复了流程图的语法:
|
||||
|
||||
## 完整操作流程
|
||||
|
||||
### **第一步:生成SSH密钥(在新电脑上)**
|
||||
|
||||
```bash
|
||||
# 1. 生成SSH密钥(使用ed25519算法,更安全)
|
||||
ssh-keygen -t ed25519 -C "renjianbo@example.com"
|
||||
|
||||
# 按提示操作:
|
||||
# - 直接回车使用默认路径 (~/.ssh/id_ed25519)
|
||||
# - 可以设置密码(可选)
|
||||
# - 再次确认密码
|
||||
|
||||
# 2. 查看公钥并复制
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
```
|
||||
**输出示例:**
|
||||
```
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJL...你的公钥内容... renjianbo@example.com
|
||||
```
|
||||
|
||||
### **第二步:添加公钥到Gerrit账户**
|
||||
|
||||
1. 登录 Gerrit:`http://101.43.95.130:8080/`
|
||||
2. 点击右上角 **renjianbo** → **Settings** → **SSH Keys**
|
||||
3. 点击 **Add Key** 按钮
|
||||
4. 粘贴复制的公钥内容,保存
|
||||
|
||||
### **第三步:克隆项目**
|
||||
|
||||
#### **方式A:SSH协议(推荐)**
|
||||
```bash
|
||||
# 使用你的用户名 renjianbo
|
||||
git clone ssh://renjianbo@101.43.95.130:29418/zhini_im
|
||||
```
|
||||
|
||||
#### **方式B:HTTP协议(备用)**
|
||||
```bash
|
||||
git clone http://101.43.95.130:8080/zhini_im
|
||||
# 可能需要输入用户名密码
|
||||
```
|
||||
|
||||
### **第四步:验证和配置**
|
||||
|
||||
```bash
|
||||
# 1. 进入项目目录
|
||||
cd zhini_im
|
||||
|
||||
# 2. 查看远程仓库地址
|
||||
git remote -v
|
||||
# 应该显示类似:origin ssh://renjianbo@101.43.95.130:29418/zhini_im
|
||||
|
||||
# 3. 配置用户信息(重要!)
|
||||
git config user.name "renjianbo"
|
||||
git config user.email "renjianbo@example.com" # 使用你的Gerrit注册邮箱
|
||||
|
||||
# 4. 可选:验证SSH连接
|
||||
ssh -p 29418 renjianbo@101.43.95.130
|
||||
# 如果看到 Gerrit 欢迎信息,说明连接成功
|
||||
```
|
||||
|
||||
## **操作流程图**
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
Start[开始] --> GenKey[生成SSH密钥<br>ssh-keygen]
|
||||
GenKey --> CopyKey[复制公钥<br>cat ~/.ssh/id_ed25519.pub]
|
||||
CopyKey --> LoginGerrit[登录Gerrit网页]
|
||||
LoginGerrit --> AddKey[添加公钥到SSH Keys]
|
||||
|
||||
AddKey --> ChooseMethod{选择克隆方式}
|
||||
ChooseMethod --> SSH[SSH协议<br>git clone ssh://renjianbo@...]
|
||||
ChooseMethod --> HTTP[HTTP协议<br>git clone http://...]
|
||||
|
||||
SSH --> Verify[进入目录验证]
|
||||
HTTP --> Verify
|
||||
Verify --> Config[配置用户信息]
|
||||
Config --> Done[完成]
|
||||
```
|
||||
|
||||
## **常见问题解决**
|
||||
|
||||
### **1. SSH连接被拒绝**
|
||||
```bash
|
||||
# 测试SSH连接
|
||||
ssh -p 29418 -T renjianbo@101.43.95.130
|
||||
|
||||
# 如果提示"Permission denied",检查:
|
||||
# - 公钥是否正确添加到Gerrit
|
||||
# - 用户名是否正确(不是admin,是renjianbo)
|
||||
# - 是否有仓库访问权限
|
||||
```
|
||||
|
||||
### **2. 首次连接需要确认主机**
|
||||
```
|
||||
The authenticity of host '[101.43.95.130]:29418' can't be established.
|
||||
ECDSA key fingerprint is SHA256:xxx...
|
||||
Are you sure you want to continue connecting (yes/no/[fingerprint])?
|
||||
```
|
||||
**输入:** `yes`
|
||||
|
||||
### **3. 端口被阻挡**
|
||||
- 检查防火墙是否允许29418端口
|
||||
- 在公司网络可能需要配置代理
|
||||
|
||||
### **4. 克隆速度慢**
|
||||
```bash
|
||||
# 可以尝试浅克隆(只获取最新版本)
|
||||
git clone --depth 1 ssh://renjianbo@101.43.95.130:29418/zhini_im
|
||||
```
|
||||
|
||||
## **快捷脚本**
|
||||
创建一键克隆脚本 `clone_zhini_im.sh`:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# 克隆智拟IM项目
|
||||
echo "正在克隆智拟IM项目..."
|
||||
git clone ssh://renjianbo@101.43.95.130:29418/zhini_im
|
||||
cd zhini_im
|
||||
git config user.name "renjianbo"
|
||||
git config user.email "renjianbo@example.com"
|
||||
echo "克隆完成!"
|
||||
```
|
||||
|
||||
执行:
|
||||
```bash
|
||||
chmod +x clone_zhini_im.sh
|
||||
./clone_zhini_im.sh
|
||||
```
|
||||
|
||||
按照这个流程操作,你应该能成功将项目拉到新电脑。如果遇到具体错误,可以把错误信息发给我,我会帮你诊断解决。
|
||||
Reference in New Issue
Block a user