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服务。
Logo

「智能机器人开发者大赛」官方平台,致力于为开发者和参赛选手提供赛事技术指导、行业标准解读及团队实战案例解析;聚焦智能机器人开发全栈技术闭环,助力开发者攻克技术瓶颈,促进软硬件集成、场景应用及商业化落地的深度研讨。 加入智能机器人开发者社区iRobot Developer,与全球极客并肩突破技术边界,定义机器人开发的未来范式!

更多推荐