Linux有问必答:如何修复“sshd error: could not load host key”

作者:佚名 上传时间:2019-04-04 版权申诉

Linux有问必答:如何修复“sshd error: could not load host key”

问题 :当我尝试SSH到一台远程服务器时,SSH客户端登陆失败并提示“Connection closed by X.X.X.X”。在SSH服务器那端,我看到这样的错误消息:“sshd error: could not load host key.”。这发生了什么问题,我怎样才能修复该错误?

该SSH连接错误的详细症状如下。

SSH客户端方面 :当你尝试SSH到一台远程主机时,你没有看见登录屏幕,你的SSH连接就立即关闭,并提示此消息:“Connection closed by X.X.X.X”。

SSH服务器方面 :在系统日志中,你看到如下错误消息(如,在Debian/Ubuntu上,/var/log/auth.log)。


  1. Oct 16 08 : 59 : 45 openstack sshd [ 1214 ]: error : Could not load host key : /etc/ ssh / ssh_host_rsa_key
  2. Oct 16 08 : 59 : 45 openstack sshd [ 1214 ]: error : Could not load host key : /etc/ ssh / ssh_host_dsa_key
  3. Oct 16 08 : 59 : 45 openstack sshd [ 1214 ]: error : Could not load host key : /etc/ ssh / ssh_host_ecdsa_key
  4. Oct 16 08 : 59 : 45 openstack sshd [ 1214 ]: fatal : No supported key exchange algorithms [ preauth ]

导致该问题的根源是,sshd守护进程不知怎么地不能加载SSH主机密钥了。

当OpenSSH服务器第一次安装到Linux系统时,SSH主机密钥应该会自动生成以供后续使用。如果,不管怎样,密钥生成过程没有成功完成,那就会导致这样的SSH登录问题。

让我们检查能否在相应的地方找到SSH主机密钥。


  1. $ ls - al / etc / ssh / ssh * key

如果SSH主机密钥在那里找不到,或者它们的大小被截断成为0(就像上面那样),你需要从头开始重新生成主机密钥。

重新生成SSH主机密钥

在Debian、Ubuntu或其衍生版上,你可以使用dpkg-reconfigure工具来重新生成SSH主机密钥,过程如下:


  1. $ sudo rm - r / etc / ssh / ssh * key
  2. $ sudo dpkg - reconfigure openssh - server

在CentOS、RHEL或Fedora上,你所要做的是,删除现存(有问题的)密钥,然后重启sshd服务。


  1. $ sudo rm - r / etc / ssh / ssh * key
  2. $ sudo systemctl restart sshd

另外一个重新生成SSH主机密钥的方式是,使用ssh-keygen命令来手动生成。


  1. $ sudo ssh - keygen - t rsa - f / etc / ssh / ssh_host_rsa_key
  2. $ sudo ssh - keygen - t dsa - f / etc / ssh / ssh_host_dsa_key
  3. $ sudo ssh - keygen - t ecdsa - f / etc / ssh / ssh_host_ecdsa_key

在生成新的SSH主机密钥后,确保它们能在/etc/ssh目录中找到。此时,不必重启sshd服务。


  1. $ ls - al / etc / ssh / ssh * key

现在,再试试SSH到SSH服务器吧,看看问题是否已经离你而去了。

原文发布时间:2014-11-14

本文来自云栖合作伙伴“linux中国”

免责申明:文章和图片全部来源于公开网络,如有侵权,请通知删除 server@dude6.com

用户评论
相关推荐
Linux有问必答如何修复sshd error: could not load host key
Linux有问必答:如何修复“sshd error: could not load host key” 问题 :当我尝试SSH到一
Solaris中无法启动SSH服务,报错 'sshd: Could not load host key: /etc/ssh/ssh_host_rsa_key'
该错误表明SSH服务无法加载主机密钥。解决此问题的步骤如下:首先,确认 '/etc/ssh/ssh_host_rsa_key' 文件是否存在。您可以使用以下命令检查文件是否存在:ls -l
Solaris 11
SSH
2023-12-01 02:32
Linux有问必答:如何修复Chrome的"Your profile could not be opened correctly"
Linux有问必答:如何修复Chrome的"Your profile could not be opened correctly" 提问
Linux有问必答:如何修复Chrome的"Your profile could not be opened correctly"
Linux有问必答:如何修复Chrome的"Your profile could not be opened correctly" 提问
SpringBoot Error Could not find or load main class org.apache.hadoop.mapreduce
【SpringBoot】Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster报
PDF
310KB
2021-01-15 06:13
Error A license for FCompW could not be obtained
是vs2008+intelvisualfortran11.1.065从前两天开始就出错误1ErrorAlicenseforFCompWcouldnotbeobtained.E:\456\luan1\s
ZIP
0B
2020-05-13 01:39
server.load error
测试domino邮件服务器出现的错误
JPG
0B
2018-12-28 12:59
Linux 有问必答如何修复“fatal error: openssl/aes.h: No such file or directory
Linux 有问必答:如何修复“fatal error: openssl/aes.h: No such file or directory Ques
Linux 有问必答如何Linux修复“fatal error: x264.h: No such file or directo
Linux 有问必答:如何在Linux 中修复“fatal error: x264.h: No such file or directo 提问
Linux 有问必答如何Linux修复“fatal error: lame/lame.h: No such file or dir
Linux 有问必答:如何在Linux中修复“fatal error: lame/lame.h: No such file or dir 提问