brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh-keygen -R removes the old host key when SSH shouts about a changed fingerprint

Network and access
~/tips/tip-ssh-keygen-r

ssh-keygen -R nas.local

Clears the old host key so SSH stops warning about a changed fingerprint after a reinstall.

You reinstalled a server, or gave a Raspberry Pi a fresh SD card, and SSH answers with a huge “WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED” banner. It looks scary, and it is supposed to. The banner is correct: the machine at that address now presents a different key.

The first time you connect to a server, SSH stores its public key in ~/.ssh/known_hosts. Every later connection compares the key the server shows with that stored copy. If they differ, SSH refuses to continue, because a different key is exactly what a man-in-the-middle attack looks like. A reinstall, a new SD card or a new machine on an old IP address creates the same situation, harmlessly.

Ask yourself one question: did I change this machine? If the answer is yes, remove only the old entry:

ssh-keygen -R nas.local

The matching line is deleted from known_hosts and a backup is saved as known_hosts.old. If you connect by IP address, remove that too:

ssh-keygen -R 192.168.1.164

The next connection asks whether you trust the new fingerprint. Compare it with the one the server prints; on the server, ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub shows it.

Do not delete the whole file, because it also holds every other server you know. Wiping it throws away real protection for machines that did not change. -R removes exactly one host and nothing else. If you use hashed host names (the default on some systems), -R still finds the entry, which a manual edit would not.

Stop and think. A key that changed with no reason is the one case where the warning is doing its job. Check whether someone reinstalled the machine, whether your router gave this address to a different device, or whether you are on a strange network. Only then continue.

Never disable the check with StrictHostKeyChecking no to make the message go away. That turns the protection off for every connection, which is much worse than one extra command.

Further reading: ssh-keygen manual (OpenBSD), On this site: use action check in a Tailscale SSH rule for a re-login, On this site: turn on Tailscale SSH with tailscale set –ssh, On this site: Guide: set up SSH keys and a ~/.ssh/config so you can type ssh nas and nothing else

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link