无法与 40.74.28.9 端口 22 协商:找不到匹配的主机密钥类型。他们的提议:ssh-rsa

Unable to negotiate with 40.74.28.9 port 22: no matching host key type found. Their offer: ssh-rsa

开始使用 NixOS 作为新的包管理系统后,在 Azure DevOps 存储库和 rsa ssh 密钥中使用 git 时出现以下错误:

jaroslavbezdek@mac> git pull
Unable to negotiate with 40.74.28.9 port 22: 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.

请问我能用它做什么?

根据 this post,您可以将 ssh.dev.azure.com 主机配置添加到您的 ~/.ssh/config 文件:

Final ~/.ssh/config that worked for me:

Host ssh.dev.azure.com
    HostName ssh.dev.azure.com
    User git
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes
    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa

对于 SSH,有几种不同类型的密钥和 RSA 密钥(ssh-rsa)可以支持多种签名。签名类型 ssh-rsa 是指带有 SHA-1 的 RSA,而签名类型 rsa-sha2-256 是带有 SHA-256 的 RSA,rsa-sha2-512 是带有 SHA-512 的 RSA。

在Azure DevOps的情况下,它只支持那种带有SHA-1的RSA,而SHA-1被认为是很弱的。这实质上意味着没有安全的方法可以通过 SSH 连接到它,在他们解决这个问题之前,您最好使用 HTTPS 或其他托管服务。 GitHub、GitLab 和 Bitbucket 都支持安全的身份验证方法。

如果您现在确实需要将 SSH 与 Azure DevOps 结合使用,您可以在 ~/.ssh/config 文件中添加一个条目来解决此问题:

Host ssh.dev.azure.com
    User git
    PubkeyAcceptedAlgorithms +ssh-rsa
    HostkeyAlgorithms +ssh-rsa

但是,请注意这是一种解决方法,并且已知它是不安全的,因此您应该就此问题联系 Azure DevOps 并切换到 HTTPS 直到他们这样做,或者转移到其他地方。

OpenSSH会报错 no matching host key type found. Their offer: ssh-rsa 如果它连接的服务器提供通过 ssh-rsa ( RSA/SHA1) 进行身份验证。

Azure Devops (TFS) 提供通过 ssh-rsa 进行身份验证。如 中所述,此算法不被认为是加密安全的。

因为它被认为是弱的,OpenSSH deprecated 在 2020-02-14 8.2 中使用 SHA-1

It is now possible[1] to perform chosen-prefix attacks against the SHA-1 hash algorithm for less than USDK. For this reason, we will be disabling the "ssh-rsa" public key signature algorithm that depends on SHA-1 by default in a near-future release.

Azure Devops Services 随后 announced a patch 允许 SHA-2

2021 年 5 月 5 日,Azure DevOps 文档 updated 提及使用 RSA 3072

问:这是真的吗?

¯\_(ツ)_/¯

问:支持哪些算法?

没有说任何地方。可能只有 ssh-rsa.

问:如何使用密码不安全的算法

添加这个

  HostkeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa

给你的~/.ssh/config

Host your-azure-devops-domain
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes
  HostkeyAlgorithms +ssh-rsa
  PubkeyAcceptedAlgorithms +ssh-rsa

问:Microsoft 是否知道这是一个问题?

Yes they are.

问:他们关心吗?

No it's a feature

在 NixOS 21.11 中,openSSH 已更新至 8.8p1(参见 Changelog)。 OpenSSH 弃用了 ssh-rsa 以及其他一些不安全的密码。

如果我没理解错的话,你只是在使用 nix 作为包管理器,而不是 NixOS。如果是这种情况,您可以按照其余答案中的指南进行操作(编辑 ~/.ssh/config)。

但是,当您使用 NixOS 配置服务器时,您可以通过添加到 configuration.nix:

来为 ssh 客户端重新启用 ssh-rsa
programs.ssh.extraConfig = ''
  PubkeyAcceptedAlgorithms +ssh-rsa
  HostkeyAlgorithms +ssh-rsa
''

要为您的 openssh 服务器重新启用不安全的 ssh-rsa 密码(例如,当旧客户端连接到服务器时),您只需将以下行添加到您的 configuration.nix:

services.openssh.extraConfig = ''
  PubkeyAcceptedAlgorithms +ssh-rsa
  HostkeyAlgorithms +ssh-rsa
'';

已更正发布的答案。我遇到了同样的问题,我用下面的代码片段从上面做了一个小修复:

Host YOUR-DOMAIN
Hostname YOUR-DOMAIN
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
HostKeyAlgorithms=+ssh-rsa
PubkeyAcceptedAlgorithms=+ssh-rsa

不要忘记将 YOUR-DOMAIN 替换为您在 AzureDevOps 上使用的域。

解决方法的格式不适用于 windows 10 和 git 版本 2.32.0。这段代码对我有用

主机 = Hostname.com
IdentityFile = ~/.ssh/id_rsa
IdentitiesOnly = 是
主机密钥算法 = +ssh-rsa
公钥接受算法 = +ssh-rsa

我也遇到了这个问题,这对我有用:

cd ~/.ssh/
vim config

Host [Hostname]
User [User]
PubkeyAcceptedAlgorithms +ssh-rsa
HostkeyAlgorithms +ssh-rsa

我遇到了几个主机名的问题,所以现在我的 ssh 配置文件中有几个这样的配置。

scp 或 ssh 可以使用这个

ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa  user@myhost -p 22

我在谷歌上搜索了很多关于这个错误的信息:我有 Ubuntu 22.04,这里是我所有的配置。
希望对大家有所帮助。

linux@linux:~$ cat /home/username/.ssh/config

Host *

KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512
Ciphers aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr

User username # it depends on your login; this one only for understanding

PubkeyAcceptedAlgorithms +ssh-rsa
HostkeyAlgorithms +ssh-rsa

并且:

/etc/ssh/sshd_config

# Ciphers and keying

Ciphers             aes128-cbc,3des-cbc
KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512

HostkeyAlgorithms ssh-dss,ssh-rsa
KexAlgorithms diffie-hellman-group1-sha1