sshd error

Summary

We recently encountered with ‘sshd error: could not load host key’. The fixing is quite easy in Ubuntu Linux system yet you should be careful while solving the issue.

This time we found this problem in Ubuntu 18.04 LTS Server Edition whereas the method is applicable to other Ubuntu and Debian based Linux Operating System also.

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”

Follow the given below steps to solve the issue.

Take Backup of sshd directory

First take the backup of ssh config folder. In case of any blunder, you can restore the file to previous state.

    sudo cp -rvf /etc/sshd ~/sshd-backup

    Remove ssh host key

    Remove the ssh keys file inside /etc/ssh directory.

      sudo rm /etc/ssh/ssh*key

      Regenerate ssh key

      In this step, now recreate the new ssh key files.

        sudo dpkg-reconfigure openssh-server

        Restart the openssh-server

        As we have done the changes in ssh, restart the ssh service by using given below command.

          sudo systemctl restart ssh

          Now try connecting by using ssh command to server/system. We hope it will be working!

          Read Some More Articles

          Leave a Reply

          This site uses Akismet to reduce spam. Learn how your comment data is processed.