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: HostKeyAlias stops SSH host key warnings for VMs behind one address

Network and access
~/tips/tip-ssh-hostkeyalias

Host vm1

Store a separate host key per machine when several share one address on different ports.

Port forwards on one public address are common at home: port 2201 goes to one VM, 2202 to another. ssh stores keys per host and port, but rebuilding a VM, or reaching it through a tunnel on localhost, still gives you the scary changed key warning.

HostKeyAlias tells ssh which name to use in known_hosts, whatever address you connect to:

Host vm1
    HostName example.com
    Port 2201
    HostKeyAlias vm1

Host vm1-tunnel
    HostName 127.0.0.1
    Port 9022
    HostKeyAlias vm1

Both entries now check against the same vm1 key, even though one goes over the internet and the other through a local tunnel. The man page mentions exactly this: tunnels and several servers on a single host.

You will see the alias in known_hosts instead of the address, and ssh-keygen -F vm1 finds it.

The trap is the opposite of what you want: if two different machines share an alias, ssh will happily compare them against one key and complain, or worse, you copy keys around to make the warning stop. I’d stick to one alias per real machine, so the warnings that still show up mean something.

Further reading: ssh_config man page

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