KVM VPS: Connection closed by

If you can ping your server but receive a "Connection closed by [VPS IP]" when trying to establish an SSH connection, connect to your VPS through VNC and check your /var/log/auth.log for the following error:

error: Could not load host key: /etc/ssh/ssh_host_rsa_key
error: Could not load host key: /etc/ssh/ssh_host_dsa_key
error: Could not load host key: /etc/ssh/ssh_host_ecdsa_key

If this is the case, this can be fixed easily by running the following commands:
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_key
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_rsa_key 
ssh-keygen -b 1024 -t dsa -f /etc/ssh/ssh_host_dsa_key

After you ran the commands, please reboot the server.


Also Read