Trust On First Use, formalized
~/.ssh/known_hosts stores fingerprints of every server you've connected to. The first time you connect, SSH asks you to verify the fingerprint and saves it. Every subsequent connection, SSH compares — if the fingerprint changes, you get a loud warning.
The scary banner — what it means
If a server's host key changes from what's in known_hosts, SSH refuses to connect and prints a screaming warning:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Two possibilities:
- Benign — the server was reinstalled, OS reimaged, or sshd reconfigured. The host key got regenerated.
- Hostile — someone is intercepting your connection (man in the middle).
You have to know which. If you reinstalled — fine, remove the old fingerprint with ssh-keygen -R and accept the new one. If you didn't — stop, investigate.
Pre-populating known_hosts
For automation, you don't want the interactive prompt on first connection. ssh-keyscan grabs the fingerprint and you append it to known_hosts. Or set StrictHostKeyChecking accept-new (auto-accept new hosts but still warn on changes).