My ssh keys are oldMany times I had the Idea to replace them and cleanup. Put the approach feels old not intuitive and i’m affraid of problems.
How do you manage keys and get sure they do ot get to old.
Submitted 3 weeks ago by ratatouille@feddit.org to selfhosted@lemmy.world
My ssh keys are oldMany times I had the Idea to replace them and cleanup. Put the approach feels old not intuitive and i’m affraid of problems.
How do you manage keys and get sure they do ot get to old.
I moved over to certificates a while ago.
Welp time to add this to the backlog of things I wanna do
That’s a really interesting read, thanks for sharing
So what happens when the certificate expires? Do you get locked out if you don’t have physical access?
Re-gen the keys. In this environment, you would have PKI setup and automation to handle cert renewal.
Having the certs expire is an advantage, security-wise. Auth will expire with certs, stolen creds can be instantly invalidated.
Like the other commenter said, they’re expiring regularly. Host keys expire ~monthly and there’s a cronjob to reach out to the certificate authority server to renew them. User certs expire ~daily and the first time I ssh on any given day I have to authenticate. Recently tied it to PocketID for SSO.
Do you think they are compromised? Generally you have to invalidate the public keys in any .ssh_hosts file that accepts them, and create new ones instead. I generally install .ssh_hosts on remote machines using an ansible playbook. I don’t have any automation to cycle them but I guess I would also do that with ansible if I thought it were needed.
Ansible may be old school by now, but it works for me. Maybe the cool kids are using something newer now. I want to look into nix or guix one of these days.
Man, I really need to learn ansible…
Learn Linux TV on YouTube has an awesome series on it.
nix for local machine config, Terraform for VM wrangling, and Ansible to orchestrate it all
Can you expand a little bit on that please?
Not compromised. But my key is around 20 years old. I’m a family admin and support my family since then with Linux and some selfhostung services.
Meanwhile I need an identity provider or something else and in any case ssh feels like a more of a pain to manage.
Are you running a planet-wide server farm from your 20 year old key or what? Just a few machines? If you want to regenerate your key and fixes the knownhosts files and it’s not too much hassle, then go ahead and do it. Do something else later if you want something fancier. Yes there are some hardware key encaapsulation approaches possible, some people like to use jump hosts as gateways (the remote hosts firewall block access to anything but the jump host) etc. Also people rely in part on virtual LSN security in their data centers or ISP’s.
If it’s just a few personal machines you’re probably overthinking this. I just don’t store secret keys on any remote machines, but use ssh-keygen on my laptop and ssh -A from there.
Ansible is not old-school. Shame on the person telling you that.
Wouldn’t automation based on your approach be really easy? Like correct me if I’m wrong, but I assume you just need a chron job executing ssh-keygen on your localhost, adding the new pub to ansible, rolling out and removing the old, right?
It’s possible but I haven’t felt the need, and it’s another thing that can go wrong. If I think my key may have been compromised I have much bigger problems. I should assume my whole machine is pwned and trojan’d, so I should replace the disk and reinstall everything.
I can see some benefit in using a special token to hold the key instead of just generating it on my laptop. One of these days.
The best way is to use ssh-ca and certificate based auth.
Never heard about that. I will look into that. Thanks!
The general process would look something like:
You’ll need to perform the following steps for each SSH key you are replacing:
old_id_rsa and old_id_rsa.pub (obviously use the same type name as your key, just prefix old_)~/.ssh/config, add a line telling SSH to use the old key as well as the new ones: IdentityFile ~/.ssh/old_id_rsa (change the key filename as aporopriate)ssh-keygen -t ed25519~/.ssh/id_ed25519.pub key to the authorized_keys file or equivalent mechanism. Do not remove the old public key yet.IdentityFile line from your ~/.ssh/configauthorized_keys file on each server you log in to.Depending on your threat model you’re going to want to do this more or less often, and so you may want to consider automating it with sonething like ansible if it’ll be a regular job.
- Find all of the SSH keys you want to replace.
I hate this part.
Ssh-copy-id is Our friend too
This generally referred to as Key Rotation. It applies to everything from SSH keys, to API keys in running apps.
There are automated ways to do this with ease, but it’s very simple to do with a single script, and some sort of secure key/value store (bitwarden, Vault, etcd…whatever).
The process is basically something like:
/ssh_keys/host1-private-12.1.25 and /ssh_keys/host1-public-12.1.25/ssh_keys/host1-private-12.21.25 and /ssh_keys/host1-pub-12.21.25/ssh_keys/host1-private-currentYour script can clear the old keys if needed but simply validating them in the access change serves the same effect. Up to you.
Tabula_stercore@lemmy.world 3 weeks ago
Trategie is vulnerable and deprecated. You might want to try its secure successor Strategie