sshd error could not load host key

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”

  1. First take the backup of ssh config folder. In case of any blunder, you can restore the file to previous state.
  2. sudo cp -rvf /etc/sshd ~/sshd-backup
    
  3. Remove ssh host key.
  4. sudo rm /etc/ssh/ssh*key
    
  5. Regenerate ssh key
  6. sudo dpkg-reconfigure openssh-server
    
  7. Restart the openssh-server
  8. sudo systemctl restart ssh
    

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