The SSH known_hosts file: what it does and how to manage it
Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with OpenSSH 9.6p1, November 29, 2026.
~/.ssh/known_hosts is where SSH saves the public key of every server you’ve accepted. On later connections SSH compares the server’s key with the saved one; a match proves it’s the same server, and a mismatch stops the connection with REMOTE HOST IDENTIFICATION HAS CHANGED. The file holds public keys only, so it isn’t secret.
What a line looks like
Each line is a host, a key type and the key. A plain entry for a server on a non-standard port looks like this (the port goes in brackets):
[127.0.0.1]:2222 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILYjjQC...
Many systems hash the hostname instead, so the file doesn’t reveal where you’ve been. On Ubuntu 24.04, /etc/ssh/ssh_config sets HashKnownHosts yes, and the entry our test client saved looked like this:
|1|F5ewAfrbzwDvRmnIsUWNVPTDhEg=|3iYzqW03fDF+jVkix9tMWW4bksk= ssh-ed25519 AAAAC3...
You can’t read a hashed entry, but ssh-keygen can still find and remove it.
Find, add and remove entries
| Task | Command |
|---|---|
| Is this host saved? | ssh-keygen -F server.example.com (or -F '[server]:2222' for another port) |
| Remove a host | ssh-keygen -R server.example.com |
| See a server’s key and fingerprint | ssh-keyscan -t ed25519 server.example.com | ssh-keygen -lf - |
| Add a host you’ve verified | ssh-keyscan -t ed25519 server.example.com >> ~/.ssh/known_hosts |
| Hash an existing file | ssh-keygen -H -f ~/.ssh/known_hosts |
In our test ssh-keygen -F '[127.0.0.1]:2222' found the hashed entry and printed # Host [127.0.0.1]:2222 found: line 1, and ssh-keygen -H hashed the plain entries while keeping the original as known_hosts.old. ssh-keygen -R keeps a backup the same way.
Only add a key from ssh-keyscan after checking its fingerprint against one you trust: the scan reports whatever server answers, so it can’t detect an impostor on its own.
Errors that point here
Host key verification failed: the host isn’t saved and SSH couldn’t ask you, or the key changed. Fix.WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!: the saved key doesn’t match. Fix.Warning: Permanently added ... to the list of known hosts.: not an error. SSH saved a new server after you said yes, or becauseStrictHostKeyChecking accept-newis set.
Settings that change how it works
Option in ~/.ssh/config |
Effect |
|---|---|
StrictHostKeyChecking ask |
Default: ask about new hosts, refuse changed keys |
StrictHostKeyChecking accept-new |
Add new hosts silently, still refuse changed keys |
StrictHostKeyChecking yes |
Refuse any host not already saved |
UserKnownHostsFile |
Use a different file, for example one per project |
HashKnownHosts yes |
Hash hostnames in new entries |
Avoid StrictHostKeyChecking no with UserKnownHostsFile /dev/null: together they turn the check off for every server. Our SSH config file guide shows how to set options for one host only.
FAQ
Where is the known_hosts file?
~/.ssh/known_hosts for your user on macOS and Linux, and C:\Users\you\.ssh\known_hosts on Windows. A system-wide file at /etc/ssh/ssh_known_hosts is also checked if it exists.
Can I delete known_hosts?
You can, and SSH will ask you to confirm each server again on the next connection. Removing only the entry you need with ssh-keygen -R hostname is safer, because you keep the protection for every other server.
Is known_hosts a secret?
No. It holds public keys of servers. Hashing just hides which hostnames you've connected to if someone reads the file.
