Regenerate SSH host keys
How to regenerate SSH host keys , when a server give error "connection closed" on SSH2_MSG_KEXINIT rm -f /etc/ssh/ssh_host* reboot # host key will be generated after reboot For Rocky Linux 8: Edit and comment lines in /etc/systemd/system/sshd-keygen@.service.d/disable-sshd-keygen-if-cloud-init-active.conf Or ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -q -t rsa ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -q -t ecdsa ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -q -t ed25519 systemctl restart sshd