Remix.run Logo
▲ Bender 7 hours ago

Before compiling this manually or updating your OpenSSH client, back up your existing keys and test manually to all of your oldest servers of each distribution flavor. One should have protected snapshots of all their keys regardless. Append the new key to authorized keys and avoid removing the old entry until it is verified that all systems accept the new key.

In an ideal world the trusts of public keys would be managed by a configuration management system that knows who really owns which public keys and fires alerts when unknown keys are added or added to the wrong account. Mapping should be by the public key itself and not the comment. Or configure PAM to query the SSH public keys from LDAP and cache them securely.

▲traceroute66 6 hours ago | parent | next [-]

> Append the new key to authorized keys and avoid removing the old entry until it is verified that all systems accept the new key.

Also a good time to consider migrating to using SSH certificates so you never have to play the authorized keys dance ever again. :)

Its not that difficult.

▲jeroenhd 6 hours ago | parent | next [-]

But then you need to update your SSH certificates, because I'd your key was signed by a broken algorithm, your certificate probably was as well.

Which reminds me to check my certificates, actually.

▲Bender 6 hours ago | parent | prev | next [-]

There are a number of pros and cons to each method that each person or organization will have to decide for themselves. If I list the pros and cons of each it will appear biased so I would encourage everyone to do their own extensive research on this topic before making such a change.

▲traceroute66 6 hours ago | parent [-]

Messing around with authorized keys files is inherently risk-laden. Stuff doesn't get put in. Stuff doesn't get taken out. Bad stuff gets put in by people accidentally or on-purpose.

Sure there are managed ways to do it, like `AuthorizedKeysCommand` or Ansible etc.

But for most people, especially those people allowing manual management of keys files, there are more cons than benefits of authorized keys.

▲Bender 6 hours ago | parent [-]

It is a lot more involved and nuanced. Trigger warning: I would encourage people to use their favorite LLM flavor of the day to get a more detailed answer about all the pros and cons of using traditional SSH public keys vs. SSH CA certificates.

▲traceroute66 6 hours ago | parent [-]

[dead]

▲rustyhancock 6 hours ago | parent | prev | next [-]

I can't believe I hadn't heard of SSH certificates. It does seem a nice simplification I'll look into this weekend.

I assume and hope it's as simple as setting up one key and then automatically being able to log in with any subsequently signed key.

▲traceroute66 5 hours ago | parent [-]

> I assume and hope it's as simple as setting up one key and then automatically being able to log in with any subsequently signed key.

Yes, in the most basic implementation that's it.

Obviously RTFM, but the gist is that the CA SSH Key gets defined on the server (sshd_config) side, e.g :

    TrustedUserCAKeys /etc/ssh/user_ca.pub
    AuthorizedPrincipalsFile /etc/ssh/principals
    # AuthorizedKeysFile none  # only once you're happy everything works ;)
And then yes, you can automagically log in with whatever is signed with the key(s) in `TrustedUserCAKeys` (as long as the principal defined in the signature matches one listed in `AuthorizedPrincipalsFile` – although IIRC you can wildcard `AuthorizedPrincipalsFile` so you might not even need to worry about that if you want a super-simple setup).

Then once you're happy with the basic principles and tested it out, you can do more fancy stuff like using Yubikeys as a poor-man's HSM (hardware CA) and eventually all sorts of server-side (man sshd_config) magic.

Its great ! Welcome to the dark side. ;)

▲Nnnes 3 hours ago | parent [-]

In theory, having your CA private keys on the same side as sshd wipes out the security benefits of using certs so this kind of setup is usually recommended against (you would ideally generate the CA certificate on a device that doesn't connect to anything except to sign keys, like a hardware security key as you mentioned, or at least somewhere that isn't accessible by SSH).

In practice, your client side devices may well be at more risk of loss due to theft or similar than your server is of being broken into, and it's pretty convenient to just scp your public keys over to sign them. I can reach my own CA private keys by SSH, just not via public IP address.

Here's a good resource for anyone wanting to get started with SSH certs: https://free-pmx.org/guides/ssh-certs/

▲jamesog an hour ago | parent [-]

I'm using a Yubikey as my CA which works nicely. I don't need to worry about having a machine that can be compromised. https://jamesog.net/2023/03/03/yubikey-as-an-ssh-certificate...

▲champtar 6 hours ago | parent | prev | next [-]

You do need to move your CA to bigger sizes or different type, so this time you still need to do some changes on all your systems.

▲ycombinatrix 6 hours ago | parent | prev [-]

Adding a remote dependency & new point of failure to my SSH servers? No thanks.

▲doubled112 3 hours ago | parent [-]

You can be your own certificate authority. SSH will trust whatever CA you give it the certificate for.

The CA could be on a remote server. It could also be a folder of certs and keys on your laptop, and you manage it with the openssl CLI.

▲ijustlovemath 6 hours ago | parent | prev [-]

Which configuration management system do you use?

▲Bender 6 hours ago | parent [-]

I used to use Ansible but now being retired I just have a handful of hobby nodes and that is trivial to manage with a shell script compared to the 50k+ physical servers and ungodly number of VM's most of which used LDAP for ssh keys.