修正格式
This commit is contained in:
@@ -120,6 +120,9 @@ cat ~/.ssh/id_ed25519.pub
|
||||
ssh -T git@192.168.3.189 -p 2222
|
||||
```
|
||||
|
||||
```
|
||||
ssh -T git@gitea.ishenwei.online -p 12222
|
||||
```
|
||||
---
|
||||
## 返回结果解析
|
||||
|
||||
@@ -304,3 +307,121 @@ SSH Port 2222 → Container 22
|
||||
👉 **最稳定方案:**
|
||||
> Gitea + SSH(2222)+ VS Code = 无痛开发环境
|
||||
|
||||
|
||||
|
||||
这是一个关于从 Windows 客户端通过 SSH 连接 Mac mini 上 Gitea 仓库的排错笔记。你可以将其保存为 Markdown 文件(如 `Gitea_SSH_Troubleshooting.md`)以便日后查阅。
|
||||
|
||||
---
|
||||
|
||||
# 📝 Git 排错笔记:解决 Gitea SSH 连接断开与权限问题
|
||||
|
||||
## 1. 问题现象
|
||||
|
||||
在 Windows 终端执行 `git clone` 或 `git pull` 时,出现以下错误:
|
||||
|
||||
- **现象 A:** `Connection closed by 192.168.3.189 port 22` 或 `fatal: Could not read from remote repository`.
|
||||
|
||||
- **现象 B:** `ishen@192.168.3.189: Permission denied (publickey)`.
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 2. 核心原因分析
|
||||
|
||||
经过排查,导致问题的根源有三点:
|
||||
|
||||
1. **端口冲突**:默认 SSH 使用 22 端口(指向 macOS 系统 SSH),而 Gitea 运行在 **2222 端口**。
|
||||
|
||||
2. **用户混淆**:Git 默认尝试使用 Windows 当前用户名(`ishen`),但 Gitea 的 SSH 验证强制要求使用 **`git`** 用户。
|
||||
|
||||
3. **协议格式**:在非标准端口(非 22)下,必须使用特定的 `ssh://` 前缀格式。
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 3. 修复步骤
|
||||
|
||||
### 第一步:验证 SSH 连通性
|
||||
|
||||
首先确认公钥是否已在 Gitea 中生效,并指定正确端口:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
ssh -vT git@192.168.3.189 -p 2222
|
||||
```
|
||||
|
||||
- **预期输出**:`Hi there, admin! You've successfully authenticated... but Gitea does not provide shell access.`
|
||||
|
||||
- **结论**:只要看到这段话,说明密钥(Key)和端口(Port)是通的。
|
||||
|
||||
|
||||
### 第二步:修正远程仓库地址 (Remote URL)
|
||||
|
||||
如果已经克隆了仓库但无法 Pull/Push,需要更新 `origin` 的地址:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
# 切换到项目目录
|
||||
cd D:\Workspace\nexus
|
||||
|
||||
# 重新设置远程地址,强制指定 git 用户和 2222 端口
|
||||
git remote set-url origin ssh://git@192.168.3.189:2222/admin/nexus.git
|
||||
```
|
||||
|
||||
### 第三步:验证修改
|
||||
|
||||
查看当前的远程配置是否正确:
|
||||
|
||||
Bash
|
||||
|
||||
```
|
||||
git remote -v
|
||||
```
|
||||
|
||||
- **正确结果应包含**:`ssh://git@192.168.3.189:2222/...`
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 4. 终极解决方案:配置 SSH Config (推荐)
|
||||
|
||||
为了避免每次都要手动输入端口和用户,在 Windows 本地创建或修改 `C:\Users\ishen\.ssh\config` 文件:
|
||||
|
||||
Plaintext
|
||||
|
||||
```
|
||||
# Mac mini Gitea 配置
|
||||
Host 192.168.3.189
|
||||
HostName 192.168.3.189
|
||||
User git
|
||||
Port 2222
|
||||
IdentityFile ~/.ssh/id_rsa
|
||||
```
|
||||
|
||||
**配置后的效果:**
|
||||
|
||||
以后只需执行简单的命令,Git 会自动映射 `git` 用户和 `2222` 端口:
|
||||
|
||||
- `git clone 192.168.3.189:admin/nexus.git`
|
||||
|
||||
- `git pull`
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 5. 总结备忘
|
||||
|
||||
- **不要使用系统用户名**:无论你的 Gitea 账户叫什么,SSH 连接用户名统一用 `git`。
|
||||
|
||||
- **非标端口必须加协议**:如果端口不是 22,地址必须写成 `ssh://git@host:port/repo.git`。
|
||||
|
||||
- **优先检查端口**:Mac 系统的 SSH (22) 和 Gitea 的 SSH (通常是 2222 或 10022) 是两码事。
|
||||
|
||||
|
||||
---
|
||||
|
||||
**记录时间**:2026-03-25
|
||||
|
||||
**设备环境**:Windows ThinkBook -> Mac mini (192.168.3.189)
|
||||
Reference in New Issue
Block a user