no matching host key type found. Their offer: ssh-rsa,ssh-dss fatal: Could not read from remote repository.
时间: 2025-01-14 22:11:15 浏览: 216
### 解决 SSH 连接远程仓库时遇到的主机密钥类型不匹配问题
当尝试通过 Git 克隆远程仓库时,如果收到错误 `no matching host key type found. Their offer: ssh-rsa,ssh-dss`,这通常是因为客户端和服务器之间的 SSH 密钥算法不兼容。现代版本的 OpenSSH 默认禁用了某些较旧的加密算法,如 `ssh-rsa` 和 `ssh-dss`。
为了修复此问题,可以在本地 SSH 配置文件中启用这些算法:
#### 修改 SSH 配置文件
编辑或创建位于用户主目录下的 `.ssh/config` 文件,并添加如下配置:
```bash
Host *
HostKeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
```
这段配置允许使用 `ssh-rsa` 算法作为主机密钥验证方法以及公钥认证方式[^4]。
#### 测试连接
完成上述更改后,可以再次尝试克隆仓库来检验是否解决了该问题。也可以先运行以下命令测试与目标服务器的连通性:
```bash
ssh -T [email protected]
```
这条命令会建立一个到 GitHub 的安全 Shell (SSH) 会话并显示一条消息确认身份验证成功与否。
相关问题
no matching host key type found. Their offer: ssh-rsa fatal: Could not read from remote repository.
It seems that you are facing an issue with SSH authentication. The error message "no matching host key type found" suggests that the SSH server's host key type is not supported by your SSH client.
To resolve this issue, you can try the following steps:
1. Specify a preferred host key algorithm in your SSH configuration file (`~/.ssh/config`). Add the following line and save the file:
```
HostkeyAlgorithms +ssh-rsa
```
2. If the above step doesn't work, you can try adding other supported host key algorithms to the configuration file. For example:
```
HostkeyAlgorithms +ssh-rsa,ssh-ed25519,ecdsa-sha2-nistp256
```
3. If you have access to the server, you can check its SSH server configuration and ensure that it supports the desired host key algorithm(s). Consult the server documentation for instructions on how to modify the SSH server configuration.
Additionally, the error message "fatal: Could not read from remote repository" indicates that there might be an issue with accessing the remote repository. Ensure that you have the necessary permissions and that the repository exists.
If the issue persists, please provide more details about your setup and the steps you have already tried.
Unable to negotiate with 192.168.0.83 port 29418: no matching host key type found. Their offer: ssh-rsa,ssh-dss fatal: Could not read from remote repository.
### 出现问题的原因
当尝试通过 SSH 连接到 Git 的远程仓库时,如果客户端和服务器之间无法就支持的主机密钥算法达成一致,则会触发错误 `no matching host key type found`。此问题通常发生在较新的 OpenSSH 客户端版本中,默认禁用了旧版的 RSA 和 DSA 密钥类型。
---
### 解决方案
#### 方法一:修改本地 SSH 配置文件
可以通过编辑本地的 SSH 配置文件来启用对 `ssh-rsa` 类型的支持:
1. 找到并打开 SSH 配置文件:
- Windows 上的位置通常是:`C:\Program Files\Git\etc\ssh\ssh_config`
- Linux 或 macOS 上的位置通常是:`~/.ssh/config`
2. 在文件末尾添加以下内容:
```plaintext
Host *
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
```
此更改表示允许使用 `ssh-rsa` 算法作为主机密钥验证方式[^1]。
3. 保存文件后重新运行命令即可解决问题。
---
#### 方法二:临时指定 SSH 参数
如果不希望永久修改全局配置文件,可以使用 `-o` 参数临时设置选项:
```bash
git -c core.sshCommand="ssh -oHostKeyAlgorithms=+ssh-rsa -oPubkeyAcceptedAlgorithms=+ssh-rsa" pull origin main
```
上述命令会在执行过程中动态调整参数以兼容目标服务器的要求[^2]。
---
#### 方法三:更新服务器端配置(适用于有权限的情况)
如果是服务器管理员或者能够联系到管理员,建议从根源上解决该问题——即让服务器支持更现代的安全协议而非依赖老旧的 `ssh-rsa`。
具体操作如下:
- 编辑服务器上的 `/etc/ssh/sshd_config` 文件;
- 添加或确认存在以下两行配置项:
```plaintext
HostKey /etc/ssh/ssh_host_rsa_key
KexAlgorithms curve25519-sha256,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
```
- 重启 SSH 服务使改动生效:
```bash
sudo systemctl restart sshd
```
这样不仅解决了当前用户的访问障碍,还提升了整体安全性水平[^5]。
---
#### 方法四:升级客户端工具链
部分情况下可能是由于使用的 Git 版本过低所致。考虑安装最新稳定发行版的 Git 工具包可能有助于消除此类冲突现象[^4]。
对于 Windows 用户而言,可通过官方站点下载最新的 MSI 安装程序完成替换;而对于基于 Unix-like 平台的操作系统来说则推荐利用包管理器如 apt-get 或 yum 来获取最前沿版本资源。
---
### 总结
以上四种途径均可有效应对因缺乏共同认可之主机公钥认证机制所引发的相关异常状况。实际应用当中可根据具体情况选取最适合自己的处理办法加以实施。
---
阅读全文
相关推荐
















