Sometime when SSH to a remote server, your SSH client check the server’s identity by comparing the server’s public key (usually an ECDSA key) with the known keys stored in your ‘~/.ssh/known_hosts’ file. This is a security measure to prevent man-in-the-middle attacks.
There are many reasons that this can happen. The warning basically means the key for the remote host has changed, and it is warning you about a potential security risk. It also tells you that line number in your ‘known_hosts’ file where the offending key is located.
To resolve this issue, you can remove the offending key from your ‘known_hosts’ file. You can do this manually by editing the file and removing the specified line from the warning message, or you can use the ‘ssh-keygen’ command as suggested in the warning message:
ssh-keygen -f "/home/yourusename/.ssh/known_hosts" -R [hostname]
‘ssh-keygen’: is a command used to generate, manage, and convert authentication keys for SSH. Here it is used to modify the ‘known_hosts’ file.
‘-f’: this option means “filename” and is followed by the path to the ‘known_hosts’ file. The ‘known_hosts’ file is where SSH stores the public keys of remote hosts that you have connected to previously. By specifying the path with ‘-f’, you are telling ‘ssh-keygen’ which file to modify.
‘-R’: stands for ‘remove’, and is used to remove all keys belonging to a specific hostname from the ‘known_hosts’ file. In this case the host name is specified by ‘[hostname]’
Replace the ‘[hostname]’ with the hostname or IP of the remote server. This will remove the offending key for that host from your ‘known_hosts’ file. The next time you ssh into the server, your client will prompt you to accept the new key and add it to your ‘known_hosts’ file.
In summary, this is modify your local (client) side of the ‘known_hosts’ file. For example, your server has been reinstalled, so the public key stored locally has been changed, you can just use the command or manually change your local file ‘known_hosts’ to allow a fresh connection, given you know the reason of causing this issue, which is not by man-in-the-middle attacks.