Raspberry Pi SSH Host Key Changed¶
When OpenSSH reports REMOTE HOST IDENTIFICATION HAS CHANGED, first verify that you reached your Raspberry Pi and compare its host key fingerprint. A fresh OS image may generate new host keys. The same warning can appear if an IP address or .local name now points to a different device.
1. Verify the new fingerprint on the Pi¶
Read the key type and SHA256: fingerprint in the warning on your client. Then use a local console on your Pi or an existing connection whose identity you already verified. Check the Pi's hostname and IP address if you have several devices. If a .local name points somewhere unexpected, check which name the Pi is advertising.
On the Pi, run this for an ED25519 warning.
For an ECDSA or RSA warning, use /etc/ssh/ssh_host_ecdsa_key.pub or /etc/ssh/ssh_host_rsa_key.pub to match the reported key type. Compare the entire fingerprint. If it differs or you cannot obtain the fingerprint through a trusted route, stop and check the device's address and reimaging history before replacing any saved key. OpenSSH fingerprint options
2. Find the exact known_hosts entry to update¶
On the client, use the host name or address shown in the warning. The Offending ... key in line names the file that contains the saved key. For a default setup where SSH warned about pi-lab.local, run this.
Use the actual lookup name for your connection.
| How you connected | Name to pass to ssh-keygen -F or -R |
|---|---|
Default port using pi-lab.local |
pi-lab.local |
Default port using 192.168.1.42 |
192.168.1.42 |
Port 2222 using pi-lab.local |
'[pi-lab.local]:2222' |
SSH config sets HostKeyAlias |
The configured alias shown in the warning |
If the warning names a custom file, add -f followed by that path. OpenSSH can find matching entries even when their hostnames are hashed. OpenSSH known_hosts lookup, HostKeyAlias documentation
3. Remove the old entry and reconnect¶
Once the Pi's fingerprint matches the key in the warning, remove the saved keys for that one lookup name. For the default-port example, run this on the client.
Use your actual account and the same hostname, port and SSH options as before. At the next trust prompt, compare the key type and fingerprint with the values you read on the Pi. Accept it once they match. If your client uses a policy that requires the key to be installed in advance, follow that policy with the verified public host key. OpenSSH scoped key removal
In a Pi 4B test, an old key in a temporary known_hosts file triggered the warning. The fingerprint offered by the server matched the one read over a verified connection. Removing the matching hashed entry left a separate host entry in place, and the connection succeeded after the client stored the verified key.
If the next error is Permission denied (publickey), check the username and the login key your client offers. That is the next stage of the connection. SSH key and login recovery