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 -F finds a host in known_hosts

Network and access
~/tips/tip-ssh-keygen-f-find-host

ssh-keygen -F example.com

Searches known_hosts for one host name and prints the entries it finds.

I know the -R flag for throwing out an old host key. Before I delete anything, I like to see what is actually stored for that host.

The manual describes ssh-keygen -F hostname as a search for the host name, with an optional port number, in a known_hosts file, listing any occurrences found. It is the read-only counterpart of -R, which removes all keys belonging to the host from the file.

ssh-keygen -F example.com

Add -l if you want the fingerprint instead of the whole key, and -f to point at another file than the default:

ssh-keygen -F example.com -l
ssh-keygen -F 192.168.1.10 -f ~/.ssh/known_hosts

The same page lists the form -F hostname [-lv], so -v is accepted as well.

When is this useful? Mostly when ssh warns that a host key changed. Run -F first to confirm the host really is in the file and which key types are stored, then decide whether to remove the entry:

ssh-keygen -R example.com

That second command changes your file, so only run it once you know why the key changed. A changed key can be a reinstalled server, and it can also be someone sitting between you and the server.

The caveat is that -F only looks at the file it reads, and it matches the host name or address you type. A server you reach under two names, say a hostname and an IP address, can have two separate entries, so search for both.

Further reading: ssh-keygen(1)

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