How do you handle SSH host keys when servers get rebuilt often?

November 17, 2026 5 answers
Asked by 9d~mapratchet_741

Rebuilt servers can come back with new host keys, causing strict SSH checks and unattended jobs to fail. How do you handle that safely without accepting every changed key automatically?

Answers

b.748!gearwicket

For a fleet that gets rebuilt regularly, a host CA is probably the cleanest option. Generate a host key during provisioning, have the CA sign it with the hostname as a principal, and give clients an @cert-authority entry in known_hosts.

The client can then accept a new host certificate after a rebuild without trusting an arbitrary replacement key. Keep certificates short lived and protect the signing process, since a CA that signs requests indiscriminately defeats the point. You also need a way to renew certificates for servers that outlive them.

_j74~caperwrench.3:

Smallstep is one option for setting this up, including integration with an identity provider. The main work is deciding which machines are allowed to get certificates for which hostnames.

Reply to this answer
m.713!plaidgizmo

You can also distribute host public keys through provisioning instead of running a CA. Generate a fresh key on the server, publish its public key through a trusted provisioning system, then update the known_hosts files used by people and automation.

That still needs a secure way to verify the key before publication. Plan the order of the updates too, or monitoring jobs may try the new server before their trusted key list is current.

Reply to this answer
b.539!faucetcrane

For a small number of rebuilds, alerting and human approval can be reasonable. Someone should verify the new fingerprint through a trusted channel before updating the stored key. Make sure unattended jobs alert on failures, rather than quietly staying broken until somebody notices.

Reply to this answer
6e~clampstencil_429

Don't just switch off strict host key checking to make the alerts go away. It may keep the jobs running, but it also removes the warning that could reveal an unexpected server or a man in the middle.

Reply to this answer
_a83~datacrank.6

It is worth looking at the naming scheme too. Reusing a hostname for a replacement makes it look like the same endpoint with a changed identity. If each short lived server has its own name, that changes how you track and distribute its key, though clients still need a trustworthy way to verify it.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions