无法与XX.XXX.XX.XX协商:未找到匹配的主机密钥类型。他们的提议:ssh-dss

时间:2015-12-10 17:48:24

标签: ssh web-hosting

我正在尝试在我的网络主机上创建一个git存储库并在我的计算机上克隆它。这就是我的所作所为:

  1. 我在远程服务器上创建了一个存储库。
  2. 我生成了一个密钥对:ssh-keygen -t dsa
  3. 我将我的密钥添加到ssh-agent。
  4. 我已复制到~/.ssh
  5. 中的服务器公钥

    然后,在尝试运行命令git clone ssh://user@host/path-to-repository之后,我收到错误:

      

    无法与XX.XXX.XX.XX协商:未找到匹配的主机密钥类型。他们的提议:ssh-dss
      致命:无法从远程存储库中读取   请确保您拥有正确的访问权限并且存储库已存在。

    这是什么意思?

7 个答案:

答案 0 :(得分:167)

最近的openssh版本默认不推荐使用DSA密钥。您应该建议您的GIT提供商添加一些合理的主机密钥。仅依靠DSA不是一个好主意。

作为一种变通方法,您需要告诉ssh客户端您要接受DSA主机密钥,如official documentation for legacy usage中所述。您几乎没有可能,但我建议您将这些行添加到~/.ssh/config文件中:

Host your-remote-host
    HostkeyAlgorithms +ssh-dss

其他可能性是使用环境变量GIT_SSH来指定这些选项:

GIT_SSH_COMMAND="ssh -oHostKeyAlgorithms=+ssh-dss" git clone ssh://user@host/path-to-repository

答案 1 :(得分:73)

您还可以在ssh行中添加-oHostKeyAlgorithms=+ssh-dss

ssh -oHostKeyAlgorithms=+ssh-dss user@host

答案 2 :(得分:17)

对我来说这很有效:(加入"sonata-project/easy-extends-bundle": "^2.1", "sonata-project/user-bundle": "^2.2" "friendsofsymfony/user-bundle": "^1.3", "friendsofsymfony/jsrouting-bundle": "^1.6"

.ssh\config

答案 3 :(得分:8)

如果您喜欢我,并且不想制作此安全漏洞系统或用户范围,那么您可以通过在这些存储库中运行此命令,将任何配置选项添加到任何需要此功能的git repos。 (注意仅适用于git版本> = 2.10,发布于2016-09-04)

git config core.sshCommand 'ssh -oHostKeyAlgorithms=+ssh-dss'

这仅在设置回购后才有效。如果您不习惯手动添加远程(并且只想克隆),那么您可以像这样运行克隆:

GIT_SSH_COMMAND='ssh -oHostKeyAlgorithms=+ssh-dss' git clone ssh://user@host/path-to-repository

然后运行第一个命令使其永久化。

如果您没有最新版本,并且仍希望尽可能保留当地的洞,我建议推荐

export GIT_SSH_COMMAND='ssh -oHostKeyAlgorithms=+ssh-dss'

在某个文件中,说git_ssh_allow_dsa_keys.sh,并在需要时source

答案 4 :(得分:2)

我想与服务器端的解决方案进行一点合作。所以,服务器说它不支持DSA,这是因为openssh client does not activate it by default

  

OpenSSH 7.0及更高版本同样禁用ssh-dss(DSA)公钥算法。它也很弱,我们建议不要使用它。

所以,要在服务器端解决这个问题,我应该激活其他Key算法,如RSA或ECDSA。我只是在局域网中的服务器上遇到此问题。 我建议如下:

更新openssh:

yum update openssh-server

如果存在sshd_config.rpmnew,则在sshd_config中合并新配置。

验证/ etc / ssh /上是否有主机密钥。如果没有生成新的,请参阅man ssh-keygen

$ ll /etc/ssh/
total 580
-rw-r--r--. 1 root root     553185 Mar  3  2017 moduli
-rw-r--r--. 1 root root       1874 Mar  3  2017 ssh_config
drwxr-xr-x. 2 root root       4096 Apr 17 17:56 ssh_config.d
-rw-------. 1 root root       3887 Mar  3  2017 sshd_config
-rw-r-----. 1 root ssh_keys    227 Aug 30 15:33 ssh_host_ecdsa_key
-rw-r--r--. 1 root root        162 Aug 30 15:33 ssh_host_ecdsa_key.pub
-rw-r-----. 1 root ssh_keys    387 Aug 30 15:33 ssh_host_ed25519_key
-rw-r--r--. 1 root root         82 Aug 30 15:33 ssh_host_ed25519_key.pub
-rw-r-----. 1 root ssh_keys   1675 Aug 30 15:33 ssh_host_rsa_key
-rw-r--r--. 1 root root        382 Aug 30 15:33 ssh_host_rsa_key.pub

在/ etc / ssh / sshd_config中验证HostKey配置。它应该允许配置RSA和ECDSA。 (如果默认情况下所有这些都被注释,它也会允许RSA,请参阅man sshd_config HostKey的部分。

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

对于客户端,只需执行以下操作即可为ssh(不是问题中的DSA)创建密钥:

ssh-keygen

在此之后,因为有比ssh-dss(DSA)更多的选项,所以客户端openssh(> = v7)应该与RSA或更好的算法连接。

Here another good article.

这是我的第一个问题,我欢迎建议:D。

答案 5 :(得分:0)

如何指定多个算法?我问是因为git刚刚在我的工作笔记本电脑上更新(Windows 10,使用Windows的正式Git版),当我尝试将项目分支推送到Azure DevOps远程服务器时,出现了此错误。我试图推--set-upstream并得到了这个:

Unable to negotiate with 20.44.80.98 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

那么,如何将上述建议纳入其中? (作为一个快速入门,我在group14上使用了@golvok的解决方案,它可以工作,但是我真的不知道1或14更好,等等。)

答案 6 :(得分:-3)

您要么遵循上述方法,要么遵循此方法

在.ssh目录中创建配置文件并添加这些行。

host xxx.xxx
 Hostname xxx.xxx
 IdentityFile ~/.ssh/id_rsa
 User xxx
 KexAlgorithms +diffie-hellman-group1-sha1