mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
[Translated] 20141022 Linux FAQs with Answers--How to fix sshd error--could not load host key.md
This commit is contained in:
parent
1f38daf7b4
commit
cb46598875
@ -1,64 +0,0 @@
|
||||
Translating by GOLinux!
|
||||
Linux FAQs with Answers--How to fix “sshd error: could not load host key”
|
||||
================================================================================
|
||||
> **Question**: When I try to SSH to a remote server, SSH client fails with "Connection closed by X.X.X.X". On the SSH server side, I see error messages: "sshd error: could not load host key." What is going on, and how can I fix this error?
|
||||
|
||||
The detailed symptom of this SSH connection error is as follows.
|
||||
|
||||
**SSH client side**: when you attempt to SSH to a remote host, you don't see login screen, and your SSH connection is closed right away with a message: "Connection closed by X.X.X.X"
|
||||
|
||||
**SSH server side**: in a system log, you see the following error messages (e.g., /var/log/auth.log on Debian/Ubuntu).
|
||||
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: fatal: No supported key exchange algorithms [preauth]
|
||||
|
||||
The root cause of this problem is that sshd daemon somehow is not able to load SSH host keys.
|
||||
|
||||
When OpenSSH server is first installed on Linux system, SSH host keys should automatically be generated for subsequent use. If, however, key generation was not finished successfully, that can cause SSH login problems like this.
|
||||
|
||||
Let's check if SSH host keys are found where they should be.
|
||||
|
||||
$ ls -al /etc/ssh/ssh*key
|
||||
|
||||
![](https://farm4.staticflickr.com/3931/15367231099_61b9087256_z.jpg)
|
||||
|
||||
If SSH host keys are not found there, or their size is all truncated to zero (like above), you need to regenerate SSH host keys from scratch.
|
||||
|
||||
### Regenerate SSH Host Keys ###
|
||||
|
||||
On Debian, Ubuntu or their derivatives, you can use dpkg-reconfigure tool to regenerate SSH host keys as follows.
|
||||
|
||||
$ sudo rm -r /etc/ssh/ssh*key
|
||||
$ sudo dpkg-reconfigure openssh-server
|
||||
|
||||
![](https://farm4.staticflickr.com/3931/15551179631_363e6a9047_z.jpg)
|
||||
|
||||
On CentOS, RHEL or Fedora, all you have to do is to restart sshd after removing existing (problematic) keys.
|
||||
|
||||
$ sudo rm -r /etc/ssh/ssh*key
|
||||
$ sudo systemctl restart sshd
|
||||
|
||||
An alternative way to regenerate SSH host keys is to manually generate them using ssh-keygen command.
|
||||
|
||||
$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
||||
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
||||
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
|
||||
|
||||
![](https://farm6.staticflickr.com/5603/15367844767_cdfd9716c8_z.jpg)
|
||||
|
||||
Once new SSH host keys are generated, make sure that they are found in /etc/ssh directory. There is no need to restart sshd at this point.
|
||||
|
||||
$ ls -al /etc/ssh/ssh*key
|
||||
|
||||
Now try to SSH again to the SSH server to see if the problem is gone.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,63 @@
|
||||
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)。
|
||||
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_dsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
|
||||
Oct 16 08:59:45 openstack sshd[1214]: fatal: No supported key exchange algorithms [preauth]
|
||||
|
||||
导致该问题的根源是,sshd守护进程不知怎么地不能加载SSH主机密钥了。
|
||||
|
||||
当OpenSSH服务器第一次安装到Linux系统时,SSH主机密钥应该会自动生成以供后续使用。如果,不管怎样,密钥生成过程没有成功完成,那就会导致这样的SSH登录问题。
|
||||
|
||||
让我们检查能否在相应的地方找到SSH主机密钥。
|
||||
|
||||
$ ls -al /etc/ssh/ssh*key
|
||||
|
||||
![](https://farm4.staticflickr.com/3931/15367231099_61b9087256_z.jpg)
|
||||
|
||||
如果SSH主机密钥在那里找不到,或者它们的大小被切短成为0(就像上面那样),你需要从头开始重新生成主机密钥。
|
||||
|
||||
### 重新生成SSH主机密钥 ###
|
||||
|
||||
在Debian、Ubuntu或其衍生版上,你可以使用dpkg-reconfigure工具来重新生成SSH主机密钥,过程如下:
|
||||
|
||||
$ sudo rm -r /etc/ssh/ssh*key
|
||||
$ sudo dpkg-reconfigure openssh-server
|
||||
|
||||
![](https://farm4.staticflickr.com/3931/15551179631_363e6a9047_z.jpg)
|
||||
|
||||
在CentOS、RHEL或Fedora上,你所要做的是,删除现存(有问题的)密钥,然后重启sshd服务。
|
||||
|
||||
$ sudo rm -r /etc/ssh/ssh*key
|
||||
$ sudo systemctl restart sshd
|
||||
|
||||
另外一个重新生成SSH主机密钥的方式是,使用ssh-keygen命令来手动生成。
|
||||
|
||||
$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
||||
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
||||
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
|
||||
|
||||
![](https://farm6.staticflickr.com/5603/15367844767_cdfd9716c8_z.jpg)
|
||||
|
||||
在生成新的SSH主机密钥后,确保它们能在/etc/ssh目录中找到。此时,不必重启sshd服务。
|
||||
|
||||
$ ls -al /etc/ssh/ssh*key
|
||||
|
||||
现在,再试试SSH到SSH服务器吧,看看问题是否已经离你而去了。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://ask.xmodulo.com/sshd-error-could-not-load-host-key.html
|
||||
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user