原文发表于cu:2016-05-24

现象:启动sshd服务时,虽看似服务启动成功,但客户端并不能连接上sshd服务器端。如下:

[root@aefe8007a17d ~]# /usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

原因:
1. 从提示信息看是sshd守护进程不能加载主机密钥文件,因为找不到这些密钥文件(配置文件/etc/ssh/sshd_config中已定义密钥文件名与路径);
2. 一般openssh服务正常安装后,主机会自动生成相应的主机密钥文件,但这里因未知原因并没有完成这一步动作,导致无法远程ssh连接。
ps:检查密钥文件是否存在(还有一种现象为:密钥文件存在,但文件大小为0):

[root@aefe8007a17d ~]# ll /etc/ssh/
total 252
-rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
-rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
-rw------- 1 root root 4361 Mar 21 22:18 sshd_config

解决方案,重新生成主机密钥文件:
1. 生成rsa_key (-t表示生成的密钥所使用的加密类型;-f项后接要生成的密钥文件名);

[root@aefe8007a17d ~]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
5e:2d:19:51:b1:e3:e0:60:65:53:e4:14:f8:d8:38:af root@aefe8007a17d
The key's randomart image is:
+--[ RSA 2048]----+
| ==Bo |
| o.= . |
| o o=+ |
| . o+*o. |
| S =oo |
| . . .. |
| . . |
| E |
| |
+-----------------+
[root@aefe8007a17d ~]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

2. 生成ecdsa_key;

[root@aefe8007a17d ~]# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

3. 生成ed25519_key。

[root@aefe8007a17d ~]# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

验证:

1. 再次检查密钥文件是否存在且合规,可以看到已生成相应主机密钥文件(实际上主机密钥文件为私钥,.pub文件为公钥):

[root@aefe8007a17d ~]# ll /etc/ssh/
total 276
-rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
-rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
-rw------- 1 root root 227 May 22 16:48 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 179 May 22 16:48 ssh_host_ecdsa_key.pub
-rw------- 1 root root 411 May 22 16:48 ssh_host_ed25519_key
-rw-r--r-- 1 root root 99 May 22 16:48 ssh_host_ed25519_key.pub
-rw------- 1 root root 1679 May 22 16:48 ssh_host_rsa_key
-rw-r--r-- 1 root root 399 May 22 16:48 ssh_host_rsa_key.pub
-rw------- 1 root root 4361 Mar 21 22:18 sshd_config

2. 此时客户端可ssh连接上sshd服务器端:

[root@localhost ~]# ssh 172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
ECDSA key fingerprint is 37:2a:69:46:c4:bd:92:b2:43:b4:cc:42:41:8e:12:2e.
Are you sure you want to continue connecting (yes/no)?

启动sshd时,报“Could not load host key”错的更多相关文章

  1. sshd 启动后 出现:Could not load host key: /etc/ssh/ssh_host_rsa_key

    今天在启动sshd时,出现了如下问题,导致客户端不能成功连接服务端,不能建立ssh连接: 有两个提示 Could not load host key: /etc/ssh/ssh_host_rsa_ke ...

  2. [转] Linux有问必答:如何修复“sshd error: could not load host key”

    编译自:http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html作者: GOLinux 本文地址:https://linux.cn/ ...

  3. 如何修复“sshd error: could not load host key”

    问题:当我尝试SSH到一台远程服务器时,SSH客户端登陆失败并提示“Connection closed by X.X.X.X”.在SSH服务器那端,我看到这样的错误消息:“sshd error: co ...

  4. sshd启动报错Could not load host key

    ~ # /usr/sbin/sshd Could not load host key: /etc/ssh/ssh_host_rsa_key Could not load host key: /etc/ ...

  5. 启动eclipse时出现“Failed to load the JNI shared library jvm.dll”错误及解决-及eclipse版本查看

    启动eclipse时出现“Failed to load the JNI shared library jvm.dll”错误及解决-及eclipse版本查看 学习了:https://www.cnblog ...

  6. xvfb启动PyQt4程序报Unable to load library icui18n错误

    xvfb启动PyQt4程序报如下错误: Unable to load library icui18n "Cannot load library icui18n: (libicui18n.so ...

  7. SSH 登录时出现如下错误:Host key verification failed

       注意:本文相关 Linux 配置及说明已在 CentOS 6.5 64 位操作系统中进行过测试.其它类型及版本操作系统配置可能有所差异,具体情况请参阅相应操作系统官方文档. 问题描述 使用 SS ...

  8. 阿里云服务器教程–SSH 登录时出现如下错误:Host key verification failed

    注意:本文相关 Linux 配置及说明已在 CentOS 6.5 64 位操作系统中进行过测试.其它类型及版本操作系统配置可能有所差异,具体情况请参阅相应操作系统官方文档. 问题描述 使用 SSH 登 ...

  9. 启动eclipse时出现“Failed to load the JNI shared library jvm.dll”错误及解决

    昨晚安装另一个版本的eclipse,启动时出现了"Failed to load the JNI shared library jvm.dll"错误: 1.刚开始以为是因为当时没有将 ...

随机推荐

  1. POJ 1384 Intervals (区间差分约束,根据不等式建图,然后跑spfa)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1384 Intervals Time Limit: 10000/5000 MS (Java/Others ...

  2. linux 编译ffmpeg 支持x264, x265

    1. 前言 本教程涉及的ffmpeg, x264, x265 2. 环境依赖 2.1 删除系统中安装的ffmpeg等库 sudo apt-get --purge remove ffmpeg mplay ...

  3. CentOS7 搭建RabbitMQ集群 后台管理 历史消费记录查看

    简介 通过 Erlang 的分布式特性(通过 magic cookie 认证节点)进行 RabbitMQ 集群,各 RabbitMQ 服务为对等节点,即每个节点都提供服务给客户端连接,进行消息发送与接 ...

  4. JS知识点整理(一)

    前言 本文把平时的一些读书笔记和理解进行了整理归纳,包含一些易混淆.遗漏的知识点,也会配上一些例子,可能不是很完整,还会有点杂,但也许会有你需要的(目前先整理了一部分,笔记有点多,后续会持续更新). ...

  5. Xcode 控制台打印Unicode字符串转换为中文

    在Xcode的控制台里直接打印一个数组或者字典,输出的都是一些Unicode的编码,不方便调试.    要想看到中文,则要去获取对应的key或者数组下标.得到具体某一个对象才能看到中文,给我们调试起来 ...

  6. 使用属性Props完成一张卡片

    一:我们先安装bootstrap,为了使我们的样式好看些 cnpm  install bootstrap  --save 二:我们在index.js中引入bootstap Import ‘bootst ...

  7. 二进制mysql安装相关知识

    建议安装5.x版本 高版本没安装经验的慎用 1.1 关闭防火墙systemctl stop firewalld.service #停止firewall#慎用 systemctl disable fir ...

  8. 【转】:ZooKeeper真不是最终一致性的,而是顺序一致性

    转:ZooKeeper真不是最终一致性的,而是顺序一致性 关键字:ZooKeeper / 分布式系统的一致性 我们可以这么理解 ZooKeeper,从整体(read 操作 +write 操作)上来说是 ...

  9. vim插件管理 - vim-plug

    vim-plug是一款轻量的vim插件管理工具. GitHub:https://github.com/junegunn/vim-plug 插件的安装 unix curl -fLo ~/.vim/aut ...

  10. redis、Memcached、MongoDb使用心得

    最近在思考数据库以及缓存的问题,发现这些知识点其实是有一点关联的,于是这篇文章通过一个连环提问的方式将这些知识点串联起来. 问:为什么要用 Memcached.Redis,直接用 MySQL 这些数据 ...