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 -H hashes the host names in known_hosts

Network and access
~/tips/tip-ssh-keygen-hash-known-hosts

ssh-keygen -H -f ~/.ssh/known_hosts

Turns the host names in known_hosts into hashes so the file no longer lists your servers.

My known_hosts file is a tidy list of every server I ever connected to. That helps me, and it helps anyone who gets a copy of the file just as much.

The -H option of ssh-keygen replaces the host names and addresses in a known_hosts file with hashes. The original content moves to a file with a .old suffix.

ssh-keygen -H -f ~/.ssh/known_hosts

You can still look up a host in the hashed file with -F and remove one with -R:

ssh-keygen -F nas.example.com
ssh-keygen -R nas.example.com

New entries are not hashed on their own. For that, set HashKnownHosts yes in ~/.ssh/config. The default is no, which is why a fresh file reads like a list.

Host *
    HashKnownHosts yes

Two things to watch. The .old file still holds the readable list, so once you have checked that all your hosts still connect, move it somewhere safe or remove it yourself. And a hash of a name someone can guess is easy to confirm: they hash their candidate and compare. Hashing hides the list from a casual look and no more than that. The .old file is also the quickest way back if the hashed file turns out wrong, so keep it until you are sure.

Further reading: ssh-keygen(1), ssh_config(5)

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