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