After a long gap of time,encountering with ‘sshd error: could not load host key’. The fixing is quite easy in Ubuntu system yet you shuold be careful while solving the issue.
This time we found this problem in Ubuntu 18.04 LTS Server Edition.
Sep 29 16:01:28 lab sshd[1088]: error: key_load_private: invalid format Sep 29 16:01:28 lab sshd[1088]: error: key_load_public: invalid format Sep 29 16:01:28 lab sshd[1088]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key Sep 29 16:01:28 lab sshd[1088]: error: key_load_private: invalid format Sep 29 16:01:28 lab sshd[1088]: error: key_load_public: invalid format Sep 29 16:01:28 lab sshd[1088]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key Sep 29 16:01:28 lab sshd[1088]: error: key_load_private: invalid format Sep 29 16:01:28 lab sshd[1088]: error: key_load_public: invalid format Sep 29 16:01:28 lab sshd[1088]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key Sep 29 16:01:28 lab sshd[1088]: fatal: No supported key exchange algorithms [preauth]
How to fix “sshd error: could not load host key”
- First take the backup of ssh config folder. In case of any blunder, you can restore the file to previous state.
- Remove ssh host key.
- Regenerate ssh key
- Restart the openssh-server
sudo cp -rvf /etc/sshd ~/sshd-backup
sudo rm /etc/ssh/ssh*key
sudo dpkg-reconfigure openssh-server
sudo systemctl restart ssh
Now try connecting by using ssh command to server/system.Hope it will be working!