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-keyscan fetches a server's host keys so you can check fingerprints

Network and access
~/tips/tip-ssh-keyscan-host-key-fingerprint

ssh-keyscan -t ed25519 example.com | ssh-keygen -lf -

Downloads the public host keys of a server, so you can inspect their fingerprints before trusting it.

The first time you connect to a server, SSH asks whether you trust its fingerprint, and almost everybody types yes. ssh-keyscan lets you look at the key first.

ssh-keyscan -t ed25519 example.com
ssh-keyscan -t ed25519 example.com | ssh-keygen -lf -

The OpenSSH manual calls it a utility for gathering the public SSH host keys of a number of hosts. -t picks the key type, such as ed25519, ecdsa or rsa. Without it you get all supported types. -p sets the port, and -H hashes the host names in the output so a known_hosts file does not reveal them.

The second command above pipes the key into ssh-keygen -lf -, which prints the fingerprint. Compare that with the fingerprint you got from the owner of the server, or from its console, and only then add the key to your known_hosts.

It is also useful in automation, for example to put a Git host in known_hosts for a CI job.

The caveat is the one the manual gives itself: ssh-keyscan cannot verify the authenticity of the host keys it gets. Somebody who can intercept your traffic can hand you their own keys, and the tool will print them happily. Building a known_hosts file blindly leaves you open to a man-in-the-middle attack. So verify the fingerprint over another channel, such as the provider’s website or a console.

Further reading: OpenBSD manual: ssh-keyscan

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