解决" Could not load host key

作者: whisshe | 来源:发表于2018-06-06 16:17 被阅读83次

    问题详情

    今天一名开发人员,需要向服务器上上传文件。使用的软件为leapftp,传输协议为sftp,使用用户名+密码进行登录。但是进行连接时,客户端报错transfer aborted by user,但是另外一名同事使用winscp能够正常进行连接和传送文件。

    解决过程

    首先登录服务器查看ssh的登录日志

    • RedHat/CentOS的登录日志在/var/log/secure

    • Debian/Ubuntu的登录日志在/var/log/auth.log

    • 错误日志如下

      error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
      

    这是因为新版的opensshd 中添加了ed25519 做签名验证,而之前系统里没这个算法的证书。生成一下就好了

    • 解决方法很简单

        ssh-keygen -A
        - 或者
        ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ED25519_key
        - 然后
        service sshd restart
      

    然后重新进行登录,发现日志出现了一个新的错误

    • 错误日志如下

      fatal: no matching cipher found: client aes192-cbc,3des-cbc,blowfish-cbc,aes128-cbc,aes256-cbc,rijndael128-cbc,rijndael192-cbc,rijndael256-cbc,rijndael-cbc@lysator.liu.se,des-cbc,des-cbc@ssh.com server aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com [preauth]
      

    这是因为缺少Cipher的加密套件,所以需要将这些加密套件加到sshd_config中。

    • 解决方法

      - 将以下内容加到/etc/ssh/sshd_config的最后
      Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,blowfish-cbc,aes128-cbc,3des-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc
      - 然后
      service sshd restart
      

    日志还是出现错误

    • 错误日志如下

      fatal: Unable to negotiate a key exchange method [preauth]
      

    这是因为还要设置SSH密钥交换算法,需要添加配置到sshd_config

    • 解决方法

      - 将以下内容加到/etc/ssh/sshd_config的最后
       KexAlgorithms diffie-hellman-group1-sha1,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1
      - 然后
      service sshd restart
      

    至此,问题全部解决完了,登录行云流水。感谢互联网

    参考

    https://unix.stackexchange.com/questions/340844/how-to-enable-diffie-hellman-group1-sha1-key-exchange-on-debian-8-0
    https://askubuntu.com/questions/626372/could-not-load-host-key-etc-ssh-ssh-host-ed25519-key-in-var-log-auth-log
    http://steronius.blogspot.com/2014/10/ssh-no-matching-cipher-found.html
    http://developer.huawei.com/ict/cn/doc/site-euleros-security-guide/index.html/zh-cn_topic_0012735926
    

    相关文章

      网友评论

      本文标题:解决" Could not load host key

      本文链接:https://www.haomeiwen.com/subject/etbbsftx.html