ssh-keygen -R <hostname>
The ssh-keygen
tool comes with an option for this already, there is no need for esoteric one-liners that are hard to remember.
Say you ssh server.example.com
and its host key has changed because you just reinstalled it. Run ssh-keygen -R server.example.com
then try to connect to the server again, you'll be presented with the option to save the host key just like new.
sed -i 18d .ssh/known_hosts