The detailed symptom of this SSH connection error is as follows.
SSH client side: when you attempt to SSH to a remote host, you don't see login screen, and your SSH connection is closed right away with a message: "Connection closed by XXXX" or "Connection reset by XXXX"
SSH server side: in a system log, you see the following error messages.
In /var/log/auth.log on Debian, Ubuntu or Linux Mint:
Oct 16 08:59:45 openstack sshd: error: Could not load host key: /etc/ssh/ssh_host_rsa_key Oct 16 08:59:45 openstack sshd: error: Could not load host key: /etc/ssh/ssh_host_dsa_key Oct 16 08:59:45 openstack sshd: error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key Oct 16 08:59:45 openstack sshd: fatal: No supported key exchange algorithms [preauth]
In /var/log/secure on CentOS, Fedora or RHEL:
Feb 18 21:48:25 localhost sshd: fatal: No supported key exchange algorithms [preauth]
The root cause of this problem is that sshd daemon somehow is not able to load SSH host keys.
When OpenSSH server is first installed on Linux system, SSH host keys should automatically be generated for subsequent use. If, however, key generation was not finished successfully, that can cause SSH login problems like this.
Let's check if SSH host keys are found where they should be.
If SSH host keys are not found there, or their size is all truncated to zero (like above), you need to regenerate SSH host keys from scratch.
Regenerate SSH Host Keys
On Debian, Ubuntu or their derivatives, you can use dpkg-reconfigure tool to regenerate SSH host keys as follows.
$ sudo dpkg-reconfigure openssh-server
On CentOS, RHEL or Fedora, all you have to do is to restart sshd after removing existing (problematic) keys.
$ sudo systemctl restart sshd
An alternative way to regenerate SSH host keys is to manually generate them using ssh-keygen command.
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
Once new SSH host keys are generated, make sure that they are found in /etc/ssh directory. There is no need to restart sshd at this point.
Now try to SSH again to the SSH server to see if the problem is gone.
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!