I am frequently rebuilding servers for staging and development. I connect to them with SSH for provisioning.
In the process, I'll destroy a VM, rebuild it, and provision it all over again with the new scripting.
One small issue I have is that my local machine remembers the old host key and warns me that it's changed for the hostname or IP after it's been rebuilt.
This is expected and a good thing. But irritating.
I then have to
ssh-keygen -R the local fingerprint and try to connect again to get prompted to accept a new one.
This is tedious. So I looked and learned that I can set some ssh options like
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
That fixes my workflow issue, but made me wonder how secure the whole process is in the first place.
If I just blindly accept every fingerprint that a new server sends me, am I only minimizing the Man in the Middle attack potential by blindly trusting it only once and then expecting it to be the same from there forward?
Or, other than getting the server keys through another channel before connecting the first time, is there some way to close that hole and know that the fingerprint I'm getting is actually from the server I intend?