Sometimes, for several reasons, it is necessary to renew the ssh keys of a host. Most Linux and Unix distributions create ssh keys during the installation of the OpenSSH server or similar packages. If you want to clone a VM in KVM or a container system these keys should be changed.

Delete old ssh host keys

do all the steps below as root user or use sudo

rm -v /etc/ssh/ssh_host_*

dpkg-reconfigure openssh-server
Restart ssh server
systemctl restart sshd

Remove old fingerprint entry

in your local known_hosts file Use the editor of your choice to edit the ./ssh/known_hosts file, or use ssh-keygen to delete the host.

ssh-keygen -R remote-host

That’s it.