$ git clone ssh://[email protected]:29418/oplus/app/olc Cloning into 'olc'... Unable to negotiate with 172.23.4.182 port 29418: no matching host key type found. Their offer: ssh-rsa fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
时间: 2025-07-30 22:05:23 浏览: 12
在使用 Git 克隆仓库时,如果遇到 `Unable to negotiate with ... no matching host key type found. Their offer: ssh-rsa` 错误,通常是因为 SSH 客户端与服务器之间无法就使用的主机密钥类型达成一致。这类问题常见于较新版本的 OpenSSH 客户端(如 7.0 及以上版本)不再默认支持某些旧的密钥类型,例如 `ssh-rsa` 或 `ssh-dss`。
### 问题原因
SSH 服务器可能只提供 `ssh-rsa` 或 `ssh-dss` 作为主机密钥类型,而客户端配置中禁用了这些类型,导致协商失败。OpenSSH 从 8.2 版本开始默认禁用 `ssh-rsa` 算法(仅允许使用更安全的 RSA SHA-256/SHA-512)[^1]。
### 解决方法
可以通过修改本地 SSH 客户端配置文件,启用对 `ssh-rsa` 的支持来解决此问题。
#### 方法一:修改 `~/.ssh/config` 文件
在用户目录下的 `.ssh` 文件夹中编辑或创建 `config` 文件,添加以下内容:
```ssh-config
Host your.git.server.hostname
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
```
将 `your.git.server.hostname` 替换为实际的 Git 服务器地址,例如 `git.example.com`。如果希望对所有主机生效,可以将 `Host` 行改为 `*`:
```ssh-config
Host *
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
```
#### 方法二:命令行临时启用
如果不想修改配置文件,也可以通过命令行临时指定:
```bash
ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa [email protected]
```
对于 Git 命令,可以这样使用:
```bash
GIT_SSH_COMMAND="ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa" git clone [email protected]:username/repo.git
```
### 安全建议
虽然启用 `ssh-rsa` 可以解决当前问题,但该算法已被认为不够安全。建议联系服务器管理员升级服务器配置,支持更安全的密钥类型如 `rsa-sha2-512`、`ecdsa-sha2-nistp256` 或 `ed25519` [^4]。
---
###
阅读全文
相关推荐




















