SSH Error Invalid Format – Ubuntu 18.04

This article is a troubleshoot documentation about problems with SSH Server on the Ubuntu Server 18.04 operating system.

Problems:

When Ubuntu Server 18.04 has not been installed SSH Server then we install the new SSH Server package, but from the SSH Client it cannot connect and there is an error message as follows:

  • Unexpectedly closed network connection server
  • Network error: Software caused connection abort
  • Connection closed by 192.168.2.106 port 22
  • ssh: connect to host 192.168.20.106 port 22: Connection refused

Log output at: /var/log/auth.log

 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_private: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_public: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_private: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_public: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_private: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: key_load_public: invalid format
 Nov 18 03:59:56 localhost sshd[10704]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
 Nov 18 03:59:56 localhost sshd[10704]: fatal: No supported key exchange algorithms [preauth]
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_private: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_public: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: Could not load host key: /etc/ssh/ssh_host_rsa_key
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_private: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_public: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_private: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: key_load_public: invalid format
 Nov 18 04:00:27 localhost sshd[15625]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
 Nov 18 04:00:27 localhost sshd[15625]: fatal: No supported key exchange algorithms [preauth] 

Cause:

Format host key rsa,ecdsa,ed25519 are invalid / wrong.

Solution:

Generate suitable new formats:
ssh-keygen -A

Restart SSH Server Services:
systemctl restart sshd

Leave a Reply

Your email address will not be published. Required fields are marked *

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