【Linux】【ssh问题】no matching key exchange method found.

Unable to negotiate with xx.xx.xx.xx port xx: no matching key exchange method found.Their offer: diffie-hellman-group1-sha1

今天设置密钥的时候阴差阳错将匹配方式给改了,复杂的就是每个连接服务器的用户都得重新设置一下了。。设置方法如下:

Mac os

在本地

  1. sudo vim /etc/ssh/ssh_config
  2. 去掉MACs hmac-md5,hmac-sha1,umac-64@openssh.com前的"#"
  3. 在末尾加
    HostkeyAlgorithms ssh-dss,ssh-rsa
    KexAlgorithms +diffie-hellman-group1-sha1
    
  4. 这时候可以ssh xx@xxx.xxx.xx.xx可以发现错误提示已经变成下图所示:
    在这里插入图片描述
  5. 为了方便后续操作,vim /Users/xx/.ssh/known_hosts去掉以服务器ip开头的那一行,消除访问的ip记录从而重新设置。
  6. ssh-keygen -t rsa -C " "
  7. ssh-copy-id -f xxx@xxx.xxx.xx.xx后就可以连接了。

Windows

在本地

  1. 打开cmd控制命令行
  2. 输入type nul> C:\Users\用户名\.ssh\config(可以先鼠标操作确定一下目录),这样就创建好了一个无后缀的文件。
  3. 然后鼠标操作进入C:\Users\用户名\.ssh\config,用记事本打开config输入下列文字从而将方法成功添加。
    Host xx.xx.xx.xx 
    KexAlgorithms +diffie-hellman-group1-sha1
    
  4. 然后关闭文件,再次打开cmd,重新生成密钥,输入ssh-keygen -t rsa -b 4096生成SSH密钥和公钥,密钥id_rsa和公钥id_rsa.pub文件都默认保存在(C:\User\用户.ssh)文件夹下,复制公钥所在文件夹`。
  5. 公钥文件id_rsa.pub传到远程服务器的authorized_keys文件中。
    SET REMOTEHOST=xx@xxx.xxx.xx.xx
    scp xxx\.ssh\id_rsa.pub %REMOTEHOST%:~/tmp.pub
    ssh %REMOTEHOST% "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat 	~/tmp.pub >> ~/.ssh/authorized_keys && chmod 600 	~/.ssh/authorized_keys && rm -f ~/tmp.pub"
    
  6. 然后连接就可以了。

how to disable diffie-hellman-group1-sha1 for SSH

因为filezila无法打开支持该算法的服务器,所以最终决定更换算法。

  1. ssh -Q kex查看支持的匹配算法。
    diffie-hellman-group1-sha1
    diffie-hellman-group14-sha1
    diffie-hellman-group-exchange-sha1
    diffie-hellman-group-exchange-sha256
    ecdh-sha2-nistp256
    ecdh-sha2-nistp384
    ecdh-sha2-nistp521
    curve25519-sha256@libssh.org
    
  2. sudo vim /etc/ssh/sshd_config编辑最后一行KexAlgorithms,用上述除diffie-hellman-group1-sha1的其他算法去代替。
  3. service ssh restart重启SSH服务。
  • 4
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值