r/linuxadmin • u/scottchiefbaker • Feb 26 '26
Would you replace your server's SSH keys when you do an OS upgrade?
I have a handful of older servers that are running Rocky 8.x that we're slowing upgrading to Rocky 10.x. Web servers, DNS servers, infrastructure servers, etc. This involves spinning up a new VM, getting it configured, and adopting the IP of the old server. No major service changes, or configuration changes other than the modernizing the OS.
When you are upgrading Linux servers do you keep the existing SSH key, or generate a new one? As best practice I've always just generated new host keys, but that has the side effect of breaking all of the SSH trust relationships for anything automation related that connects. I always copy over the ~/.ssh/ directory, and the authorized_keys, but when the host key changes, then every remote connection needs to be updated with the new key.
I have no reason to believe the host key is compromised, so I'm leaning towards copying over the old host key just to make my life easier so I don't have to update anything that talks SSH to it.
How do you guys handle in-place upgrades like this?
14
u/Hotshot55 Feb 26 '26
If you're doing an in-place upgrade, you're going to retain all of your data, so there's really no need to replace the key.
You're either doing something wrong or have something confused here.
7
u/myelrond Feb 26 '26
As an updated server is the same entity in terms of function from the users perspective I would not rotate the keys. The keys should assure that the user is connected to the system he is expecting to and has been before and even after a major OS update this is still the same machine to provide the desired function for the user. So why make them question the connection?
5
u/cdn-sysadmin Feb 27 '26
I create a SSH CA to sign all my host keys. I keep the ssh_ca and ssh_ca_pub as pillars in saltstack, then do:
then add @cert-authority to with the ssh-host-ca-pub to /etc/ssh/ssh_known_hosts
So I never have to worry about any of this shit. I can spin up thousands servers and never have to think about TOFU or known_hosts
2
u/SudoZenWizz Feb 26 '26
Newer systems also uses newer crypto so when i’m moving to a new system i don’t take the known hosts, only authorized keys. First connection asks for new key, and accept it. If this is hard, there the option to ignore host key but this is not safe to be used. You can also have ssh-keyscan to gather new keys and you can redirect it’s output to known_hosta file (append mode >>)
2
u/fubes2000 Feb 26 '26
Side question: Would certificate auth help here? Can the server be issued a cert that is used in place of the host key?
2
u/michaelpaoli Feb 26 '26
Not typically, no. Though may occasionally/eventually want to rotate ... if nothing else, for keys that are both more secure and more efficient. Don't necessarily have to drop the old immediately after doing so, but probably want to do some kind of phase-out of older (e.g. less secure) keys.
DNSSEC + SSHFP
The automation might possibly still need a slight nudge, but automation or not, DNSSEC + SSHFP will generally quite significantly help on updating host keys.
Uhm, don't generally have to change authorized_keys when the host keys change, unless those earlier key protocols got dropped from being accepted. Though one typically will need to update known_hosts.
And if you want (and newer OS may also do so by default, at least in part), can tighten the security on what key types are accepted for authentication.
2
u/chkno Feb 26 '26
You have some credence (~low) about whether the host key has been compromised, and some target level of assurance of security (unspecified). This is all about your quality target. If this is a high-stakes, high-security environment, distribute the new key to clients and then rotate the key. If you don't already have a mature public-key distribution mechanism, then it sounds like you're not in a high-stakes/high-security environment.
2
u/EmberQuill Feb 27 '26
I don't intentionally replace host keys, but I don't put any effort into keeping them either. If upgrading a server involves just upgrading packages and rebooting, it keeps the host key. If I'm replacing the server, then the new server has a new host key and I don't bother trying to preserve the old one.
3
u/newworldlife Feb 26 '26
If the old system wasn’t compromised, I usually rotate host keys during a rebuild.
A new OS = new trust boundary for me.
Yes, it breaks known_hosts, but that’s manageable if you’re using config management or
StrictHostKeyChecking=accept-new in automation.
Copying old host keys works, but it defeats the purpose of rebuilding clean.
For production fleets, I prefer:
Slight pain once, cleaner long-term.
1
u/edthesmokebeard Feb 27 '26
Everyone just accepts whatever key the server presents them anyway, I wouldn't overthink it.
1
u/chrillefkr Feb 27 '26
New keys on new instances. Not for any in-place upgrades. Also, certificates rids you of host key validation failures
-1
u/johnklos Feb 27 '26
After what Debian did, I'd replace keys on any Debian or Debian-derived OS unless it's been done well after Debian's screwup.
0
u/[deleted] Feb 26 '26
[deleted] — view deleted comment