How to change a SSH host key?

I cloned a server and so they've the same RSA key fingerprint.

It seems to be defined in /etc/ssh/ssh_host_rsa_key.pub.

What is the correct way to change that?

Thanks.


Solution 1:

Or, remove keys and

ssh-keygen -A

Explanation:

-A: For each of the key types (rsa1, rsa, dsa, ecdsa and ed25519) for which host keys do not exist, generate the host keys with the default key file path, an empty passphrase, default bits for the key type, and default comment. This is used by /etc/rc to generate new host keys.

Solution 2:

Follow these steps to regenerate OpenSSH Host Keys

  1. Delete old ssh host keys: rm /etc/ssh/ssh_host_*
  2. Reconfigure OpenSSH Server: dpkg-reconfigure openssh-server
  3. Update all ssh client(s) ~/.ssh/known_hosts files

Reference