【问题标题】:Unable to negotiate with 40.74.28.9 port 22: no matching host key type found. Their offer: ssh-rsa无法与 40.74.28.9 端口 22 协商:找不到匹配的主机密钥类型。他们的提议:ssh-rsa
【发布时间】:2021-12-20 19:46:00
【问题描述】:

开始使用 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.

请问我能用它做什么?

【问题讨论】:

    标签: git azure-devops rsa nix


    【解决方案1】:

    使用 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,直到他们这样做,或者转移到其他地方。

    【讨论】:

    • 啊哈!这终于解决了我单独的 ssh 问题。尝试了大量其他选项。
    【解决方案2】:

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

    对我有用的最终~/.ssh/config

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

    【讨论】:

    • IdentitiesOnly yes PubkeyAcceptedAlgorithms +ssh-rsa HostkeyAlgorithms +ssh-rsa CodeCommit 设置后遇到同样的问题,粘贴以上 3 行成功通过 SSH 验证 git,谢谢!
    【解决方案3】:

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

    Azure Devops (TFS) 提供通过 ssh-rsa 进行身份验证。如the answer by bk2204 所述,此算法在密码学上不安全。

    由于它被认为很弱,OpenSSH deprecated 在 2020 年 2 月 14 日在 8.2 中使用 SHA-1

    现在可以[1] 对 SHA-1 哈希算法,价格低于 5 万美元。为此,我们将 禁用依赖于的“ssh-rsa”公钥签名算法 在不久的将来版本中默认使用 SHA-1。

    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

    【讨论】:

      【解决方案4】:

      随着 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 = ''
        PubkeyAcceptedAlogirthms +ssh-rsa
        HostkeyAlgorithms +ssh-rsa
      '';
      

      【讨论】:

        猜你喜欢
        • 2022-08-03
        • 2021-04-14
        • 2016-05-15
        • 1970-01-01
        • 1970-01-01
        • 2017-10-14
        • 2016-02-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多