原文发表于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. python codecs模块 ---处理数据写入文件时会有编码不统一的问题

    我们用open方法打开文件有时候会有一些问题,因为open打开文件只能写入str类型,而不会管字符串是什么编码方式. 示例: >>> fr = open('test.txt','a' ...

  2. java程序陷阱

    1.找奇数

  3. Microsoft Visio / Project professional 2013 官方版本(下载)

    Microsoft Visio微软开发的一款软件, 它有助于 IT 和商务专业人员轻松地可视化.分析和交流复杂信息. 它能够将难以理解的复杂文本和表格转换为一目了然的 Visio 图表. 该软件通过创 ...

  4. 理解Web应用程序的代码结构和运行原理(3)

    1.理解Web应用程序的运行原理和机制 Web应用程序是基于浏览器/服务器模式(也称B/S架构)的应用程序,它开发完成后,需要部署到Web服务器上才能正常运行,与用户交互的客户端是网页浏览器. 浏览器 ...

  5. Oracle AWR与警报系统一

    管理自动工作负荷知识库 Oracle收集大量有关性能和活动的统计信息.这些信息在内存中积累,并定期写入数据库:写入到构成自动工作负荷知识库(Automatic Workload Repository, ...

  6. 搭建Java的运行和开发环境

    Java最大的优势就是跨平台,即编译一次,就能在linux.windows和mac等平台运行,无需再次编译.而典型的C和C++ 则是源代码跨平台,需要根据不同平台的编译规范来进行编译. Java如何跨 ...

  7. C++编译器是如何管理类和对象的,类的成员函数和成员变量

    C++中的class从面向对象理论出发,将变量(属性)和函数(方法)集中定义在一起,用于描述现实世界中的类.从计算机的角度,程序依然由数据段(栈区内存)和代码段(代码区内存)构成. #include ...

  8. golang 切片小记

    1 切片初始化 func printSlice(s []int) { fmt.Printf("len=%d cap=%d underlying array:%p, %v\n", l ...

  9. 20155226 2016-2017-2 《Java程序设计》第2周学习总结

    20155226 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 了解了基本类型以及初识类类型,熟悉了注释,变量及运算符的使用. 了解了几种运算方式但还不算熟 ...

  10. 20155305 2016-2017-2《Java程序设计》课程总结

    20155305 2016-2017-2<Java程序设计>课程总结 (按顺序)每周作业链接汇总 [预备作业1](http://www.cnblogs.com/20155305ql/p/6 ...