error: Could not load host key

Recently while upgrading the OpenSSH server, we faced some issue. This time, the issue was related to ssh key and we got number of lines in message log file with information – “error: Could not load host key” .

Here are some brief detail taken from our system.

Jan 17 11:14:10 localhost sshd[6294]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jan 17 11:14:10 localhost sshd[6294]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Jan 17 11:14:22 localhost sshd[6296]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jan 17 11:14:22 localhost sshd[6296]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Jan 17 11:15:05 localhost sshd[6305]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
Jan 17 11:15:05 localhost sshd[6305]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

Solve “error: Could not load host key”

We have couple of method to solve this issue. Here, we will remove all key and restart the sshd service .

First take the backup of entire /etc/ssh directory so that we will restore back the keys.

tar -cvzf etc_ssh.tar.gz /etc/ssh

Now list the files once ,for confirmation how many ssh keys exist.

[root@localhost ssh]# ls -l /etc/ssh/ssh*key
-rw-------. 1 root root  668 Jan 17 11:17 /etc/ssh/ssh_host_dsa_key
-rw-------. 1 root root  227 Jan 17 11:17 /etc/ssh/ssh_host_ecdsa_key
-rw-------. 1 root root  419 Jan 17 11:17 /etc/ssh/ssh_host_ed25519_key
-rw-------. 1 root root  991 Jan 17 11:17 /etc/ssh/ssh_host_key
-rw-------. 1 root root 1675 Jan 17 11:17 /etc/ssh/ssh_host_rsa_key
[root@localhost ssh]#

Remove the keys file

rm /etc/ssh/ssh*key

Now restart the ssh service

systemctl restart ssh

IMPORTANT Note: Working on ssh related task is risky, when you have one method of access that is through ssh only . Always be careful while working on ssh.
1. Always connect with server via ssh with two terminal , accessing the same server.
2. Try to use screen command also
3. We do not recommend to use telnet server publicly but you can access via telnet when you do not have any physical access to server. Learn how to install telnet server.