root@server1:~# service ssh restart
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
[....] Restarting OpenBSD Secure Shell server: sshdCould not load host key: /etc/ssh/ssh_host_ecdsa_key
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
make sure size is not zero,
good example:-
root@server1:~# ls -al /etc/ssh/ssh*key
-rw------- 1 root root 668 Nov 30 18:12 /etc/ssh/ssh_host_dsa_key
-rw------- 1 root root 227 Dec 5 15:03 /etc/ssh/ssh_host_ecdsa_key
-rw------- 1 root root 1675 Nov 30 18:12 /etc/ssh/ssh_host_key
-rw------- 1 root root 1671 Nov 30 18:12 /etc/ssh/ssh_host_rsa_key
[SOLUTION - debian / ubuntu ]
root@server1:~# dpkg-reconfigure openssh-server
Creating SSH2 ECDSA key; this may take some time ...
[ ok ] Restarting OpenBSD Secure Shell server: sshd.
[SOLUTION - redhat/centos]
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
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.