We all have this problem eventually. Well, at least those of us who have
somehow ended up responsible for managing servers. Let’s say you have five
servers. Nothing particularly exciting, just a few machines doing server things.
Also assume you are a filthy heathen and doing this all manually instead of
using IaC tools like Ansible. You generate an SSH key, then run ssh-copy-id
against each of them, and you’re off to the races.
ssh-copy-id prod@test
ssh-copy-id test@production
ssh-copy-id ubuntu@supertorrenter
ssh-copy-id admin@bitcoin-miner-6
ssh-copy-id root@asic-backdoorExcellent. I can now SSH into all five servers without having to think about authentication again. Now let’s say we want to give James access. After years of being a friend with a questionable IT history, the board (I am the board) has decided to forcefully promote him to infrastructure manager of our little network. Congratulations, James, have a free CVE. Easy enough: we grab his public key, add it to the five servers, and he’s off to the races as well.
But now let’s say we work for a company. Instead of two people, we have 5, 10, maybe 50+ people who need access to various servers, all with different levels of permissions. Some need production access, some only need staging, and some probably shouldn’t be allowed anywhere near a terminal but we better give them root access just in case. The BA just called and wants to deploy their Claude Code account without going through our checks and deployment policy, no stress, we can add their keys to prod as well (once we pull the public key out of the private key they just sent us).
We might also be trying to satisfy the requirements of Essential Eight
ASD Essentials, SOC 2, or ISO 27001. Suddenly, having a bunch of public keys
scattered across hundreds of machines starts looking like a proper pain in the
ass. Now the compliance team keeps asking questions like:
- How do we manage who has access to what?
- How do we revoke access when someone leaves?
- How do we rotate keys when the BA displays it in their web app that somehow got to prod?
- Do we have access logs?
- I know you said it doesn’t affect us because we are running a Go API, but is it vulnerable to the PHP2Shell vulnerability?
- How do we audit who connected to which server and what they did?
Meanwhile, Danie has apparently siphoned all the network traffic and client data into his private analytics server, built an Excel spreadsheet and is now making a concerning amount of money on Polymarket bets. Fantastic. Maybe we should have thought about access controls a little earlier. Alternatively, here is my four weeks’ notice.
So what if, instead of having to manage everyone’s individual keys across every server, we just had one centralised machine that everyone connects through? We could put authentication on it, integrate SSO, manage access controls, collect audit logs, maybe even require a VPN, and have it connect to all the other servers on our behalf. Depending on how we set it up, we could have the bastion authenticate to our servers using a small set of managed credentials, or just forward SSH connections while our servers continue authenticating individual users.
Congratulations, we’ve reinvented the bastion host.
Bastion Hosts, Bastion Hosts Everywhere
This is where a lot of people and companies eventually end up. Some have a single bastion host. Others have several, separating different networks, environments, or security boundaries. Some have bastion hosts that connect to other bastion hosts via RDP only to RDP to other servers (yes this is a thing, no I don’t want to talk about it), because apparently we haven’t made connecting to a server complicated enough.
There are approximately a million products out there that solve this problem in one way or another. My personal favourite is Warpgate, which is a project I’ve been following for some time. It provides SSO integration, access controls, session auditing, and a bunch of other useful features.
Most companies also automate their infrastructure using tools like Ansible,
Terraform, cloud-init, or other eldritch bash scripts. Managing SSH keys
through configuration management is entirely possible, and bastion hosts
aren’t the only solution. Some people just want jump hosts which act as
gateways and then have some service that syncs its authorized_keys to an
internal key service.
But the general idea is the same: we want to stop manually maintaining access to individual machines. This is where I thought this story was going to end.
Hang On, SSH Can Do What?
I was looking through the OpenSSH sshd_config docs the other day, as one
does when waiting for your token entropy service to collapse, when I came
across something interesting: TrustedUserCAKeys
Sorry, what? Apparently, OpenSSH supports certificate authorities. Not the usual HTTPS certificates you get from Let’s Encrypt, but its own certificate format for SSH authentication.
Normally, when you authenticate using an SSH key, the server needs to know
your public key. That’s why we’ve spent all this time distributing keys into
authorized_keys files. But SSH certificates let us do something a bit
different. Instead of telling
every server to trust James’ key, my key and the keys belonging to another 3
developers, 10 PMs, 15 BAs and the backdoor account; we can tell every server
to trust one certificate authority.
That CA can then sign our public keys, producing SSH certificates that the servers can verify. The server doesn’t need to have seen our individual public keys before, it just needs to trust whoever signed them. That’s pretty interesting, and it gets even better. These certificates can have an expiry time. We could sign someone’s key and say they’re allowed to authenticate as a particular user for the next hour. After that, the cert expires and can no longer be used to establish new SSH connections.
No manually removing their public key from hundreds of servers. No distributing
a new key every time someone’s access changes. We could just issue short-lived
certificates with the appropriate principals and restrictions, and have the
servers decide what those certificates are actually allowed to access. All of
this is built directly into OpenSSH. No custom SSH daemon. No complicated
authentication plugin. Just a CA key, some configuration, and ssh-keygen.
It all sounds suspiciously easy. So naturally, I wanted to see how this works in practice and see how quickly it turns into pure pain.
Becoming a Certificate Authority
Right, so apparently we need a certificate authority. How hard can that be?
Looking through the ssh-keygen docs, it turns out a CA is just another SSH
key pair ™️ There’s no special ceremony or demonic ritual involved, just:
ssh-keygen -t ed25519 -f ssh_caDone. We’re a CA now. But this is boring. I hear there’s a vacancy in the CA business since eMudhra decided to leave, so let’s follow their example. From my extensive understanding of elliptic-curve cryptography, we just need a really big, random prime number for our private key. Something nobody would ever guess.
Let’s use 4.
It’s perfect. Not only is it not a big number, it isn’t even prime, so nobody
would possibly think to guess it. Unfortunately, ssh-keygen doesn’t support
--private-key 4 (I’ll make a PR later), so we’ll have to improvise with a bit
of Python.
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import serialization
big_random = 4
key = ec.derive_private_key(big_random, ec.SECP384R1())
with open("ssh_ca", "wb") as f:
f.write(key.private_bytes(
serialization.Encoding.PEM,
serialization.PrivateFormat.TraditionalOpenSSL,
serialization.NoEncryption(),
))
with open("ssh_ca.pub", "wb") as f:
f.write(key.public_key().public_bytes(
serialization.Encoding.OpenSSH,
serialization.PublicFormat.OpenSSH,
) + b" ssh_ca\n")Excellent. We now have a perfectly valid P-384 private key with the value 4.
Except OpenSSH apparently has a problem with this:
Load key "ssh_ca": invalid elliptic curve valueTurns out OpenSSH has been checking for embarrassingly small ECDSA private keys since at least 2011, rejecting P-384 private scalars with 192 or fewer significant bits. Which makes the whole eMudhra situation even more impressive. Apparently, someone at OpenSSH read the cryptography documentation fifteen years ago :shocked_pikachu.jpg:
Anyway, back to our boring, properly generated key.
Getting Some Servers to Trust Me
Now that we have a legit CA in the form of ssh_ca and ssh_ca.pub, we now
need some servers to trust it. I’ll spin up a server in Binarylane (not
affiliated) for a test server (forgetting I could’ve just spun one up in my
Proxmox cluster because I’m an idiot). Say hi to lorenzo-noise.
root@lorenzo-noise:~# fastfetch
_,met$$$$$gg. root@lorenzo-noise
,g$$$$$$$$$$$$$$$P. ------------------
,g$$P"" """Y$$.". OS: Debian GNU/Linux 13 (trixie) x86_64
,$$P' `$$$. Host: std-min (pc-i440fx-7.2)
',$$P ,ggs. `$$b: Kernel: Linux 6.12.85+deb13-amd64
`d$$' ,$P"' . $$$ Uptime: 11 mins
$$P d$' , $$P Packages: 325 (dpkg)
$$: $$. - ,d$$' Shell: bash 5.2.37
$$; Y$b._ _,d$P' Display (QEMU Monitor): 1280x800 @ 75 Hz in 15"
Y$$. `.`"Y$$$$P"' Terminal: /dev/pts/0
`$$b "-.__ CPU: Common KVM v5 @ 2.85 GHz
`Y$$b GPU: Unknown Device 1111 (VGA compatible)
`Y$$. Memory: 297.55 MiB / 967.36 MiB (31%)
`$$b. Swap: Disabled
`Y$$b. Disk (/): 1.05 GiB / 19.46 GiB (5%) - ext4
`"Y$b._ Local IP (eth0): 103.100.36.28/24
`"""" Locale: C.UTF-8You may not want to hear it, but this is what peak performance looks like. This
server will be destroyed by the time this post is out so don’t expect anything
when you try to attack it. My regular SSH key is already on it, so I can get
in, upload the ssh_ca.pub to /etc/ssh/ssh_ca.pub and change up some of the
/etc/ssh/sshd_config values.
PubkeyAuthentication yes
TrustedUserCAKeys /etc/ssh/ssh_ca.pub
# Disabling ~/.ssh/authorized_keys to really test this
AuthorizedKeysFile none
# Extra hardening for extra regret later
PasswordAuthentication no
KbdInteractiveAuthentication no
HostbasedAuthentication no
GSSAPIAuthentication noNow, after restarting the sshd service, it should pick up the new settings.
$ ssh root@lorenzo-noise.bnr.la
root@lorenzo-noise.bnr.la: Permission denied (publickey).Sweet. I’m now locked out completely and am in trouble if this doesn’t work.
Signing Our First Cert
Time to check out and see if this works the way I hope it does. I have my
typical SSH key pair on my computer as ~/.ssh/id_ed25519[.pub]. I just need
to use ssh-keygen to sign it:
$ ssh-keygen -s ./ssh_ca \
-I lachlan@example.com \
-n root \
-V +10m \
~/.ssh/id_ed25519.pub
Signed user key /Users/lcox74/.ssh/id_ed25519-cert.pub: id "lachlan@example.com" serial 0 for root valid from 2026-11-07T17:25:00 to 2026-11-07T17:35:00
$ ls ~/.ssh
id_ed25519
id_ed25519.pub
id_ed25519-cert.pubAs you can see it generated the id_ed25519-cert.pub file. Inspecting it will
help explain what those flags did:
$ ssh-keygen -L -f ~/.ssh/id_ed25519-cert.pub
/Users/lcox74/.ssh/id_ed25519-cert.pub:
Type: ssh-ed25519-cert-v01@openssh.com user certificate
Public key: ED25519-CERT SHA256:5q/EAE1f7vqqBgSLMcncZJ/4961m8GQXt52W8BCYY7k
Signing CA: ED25519 SHA256:E7X2Wp47yzzpxFNtcCdQBAoGKBzcIPNYCNBsS5mMSEo (using ssh-ed25519)
Key ID: "lachlan@example.com"
Serial: 0
Valid: from 2026-11-07T17:25:00 to 2026-11-07T17:35:00
Principals:
root
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rcThe -I sets the Key ID which can be used for logging, the -n is for the
Principals (roles or accounts) for access which on this server is currently
only root (yes I’m root, shoot me), finally there is -V for Validity to
set an ephemeral key. Now we can just use the id_ed25519 key as usual and it
should just work:
$ ssh -i ~/.ssh/id_ed25519 root@lorenzo-noise.bnr.la
Linux lorenzo-noise 6.12.85+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.85-1 (2026-04-30) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Nov 7 14:18:01 2026 from 203.0.113.42
root@lorenzo-noise:~# journalctl -u ssh | tail
Nov 07 14:28:13 lorenzo-noise sshd-session[17908]: error: No user for AuthorizedKeysCommand specified, skipping
Nov 07 14:28:14 lorenzo-noise sshd-session[17908]: Accepted publickey for root from 203.0.113.42 port 55970 ssh2: ED25519-CERT SHA256:5q/EAE1f7vqqBgSLMcncZJ/4961m8GQXt52W8BCYY7k ID lachlan@example.com (serial 0) CA ED25519 SHA256:E7X2Wp47yzzpxFNtcCdQBAoGKBzcIPNYCNBsS5mMSEo
Nov 07 14:28:14 lorenzo-noise sshd-session[17908]: pam_unix(sshd:session): session opened for user root(uid=0) by root(uid=0)Would you look at that. In reality, this was the second attempt, as on the first
attempt I forgot to copy the ssh_ca.pub file over first before hardening and
locking myself out.
It’s also worth looking at what actually ended up in that log. The
Accepted publickey line doesn’t just say someone logged in as root, it says
ID lachlan@example.com (serial 0) and which CA signed it. The Key ID is set by
the CA when it signs, not by whoever is holding the key, so even if the whole
company logs in as root (please don’t), the logs still say who it actually
was. That’s one of the compliance team’s questions answered for free, assuming
you have centralised logging setup… oh you don’t. Well the log only tells you
who connected though, not what they did once they got in. That’s still bastion
territory, or something with session recording like Warpgate.
Authorised Principals
We can set up some Authorized Principals by adding the
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u value to the
/etc/ssh/sshd_config. This means that we can set up a list of allowed
principals per user %u. Given that we are logging in as root (like
champions), when we log in it will check the /etc/ssh/auth_principals/root
file to see if we have the principal value. Let’s make one called admin:
mkdir -p /etc/ssh/auth_principals
echo "admin" > /etc/ssh/auth_principals/rootAfter restarting the sshd daemon, we can try logging in with the same signed
key and you’ll find that it is now rejected. We need to sign a new one with the
flag -n admin and then it will work completely fine. You can even set up
multiple principals like -n admin,deploy,dev and on login it will check if
any of them match that login user. Now principals are more like roles which
we can set on keys and for users across all the machines.
It means we’re no longer tied to managing individual public keys or even issuing certificates for specific usernames. We just need to manage which principals people are allowed to request. Fortunately, we’re ISO 27001 compliant, so we already have a perfectly maintained and up-to-date register of everyone’s access permissions. Right?
Why are you crying?
Who Actually Gets to Sign These Things?
So far, our entire authentication system depends on running ssh-keygen
manually and having the CA private key on your local machine. Some people might
call this suboptimal, others would call this production. What we want instead
is to have a centralised signing server which company staff can log in to and
have it sign your key with given principals and deal with access controls off
some sort of matrix.
There are a bunch of solutions to this already, like step-ca and HashiCorp Vault. I haven’t actually used any of these, mainly because I have only just found out about this system. I might write a solution in the coming days for entertainment’s sake, and it would probably function like:
$ sshca login
:: Opening browser for SSO...
:: Logged in as [lachlan@example.com]
:: Signed `~/.ssh/id_ed25519` for `6h`
$ ssh -i ~/.ssh/id_ed25519 root@lorenzo-noise.bnr.la
# Signed InIn reality the best solution is probably a mixture of bastion hosts and CA certs. We could have the bastion host get an ephemeral key signed with the ID of the SSO user and the principals that they are allowed instead of just using the bastion host’s main keys. I wouldn’t be surprised if this is how some of the bigger tech companies would handle this, I wouldn’t know as I am used to working with significantly smaller companies that deal with extremely legacy systems.
So, Unbastioned?
So apparently, instead of maintaining everyone’s public keys across hundreds of machines, we can just distribute one CA public key and issue short-lived certificates with the appropriate principals. We’ve solved the original problem. So let’s go back to the compliance team’s list and see how we did. Who has access to what is the principals, who connected is the Key ID in the logs, and what they did after connecting is still a mystery, so go buy a bastion.
Revoking access is mostly handled by keeping certs short-lived. If a cert only
lasts a few hours, someone who leaves just stops getting new ones. For anything
that can’t wait, sshd has RevokedKeys, which takes a Key Revocation List
(KRL) built by, you guessed it, ssh-keygen:
echo "id: danie@example.com" > revoke.txt
ssh-keygen -k -f /etc/ssh/revoked_keys -s ssh_ca.pub revoke.txtAdd RevokedKeys /etc/ssh/revoked_keys to the sshd_config and any cert with
that Key ID is rejected, expired or not. You can revoke by serial as well, which
is a good reason to give every cert a unique serial with -z instead of
leaving them all as serial 0 like I did. The catch is the KRL has to be on
every server, so we’re back to distributing a file to hundreds of machines (at
least it’s only one file).
Note: If
sshdcan’t read that file it will just refuses public key auth for everyone. I believe this is what you call, a feature.
Rotating keys is also less painful than it sounds. TrustedUserCAKeys can hold
more than one CA key, one per line, so we can add the new CA alongside the old
one, start signing with the new one, and remove the old one once its certs have
expired. If the certs are short-lived, that’s hours rather than months.
Well, except now we need to manage two certificate authorities, an SSO integration, access policies, certificate issuance, renewal, a revocation list, and probably some more YAML. I see this as an absolute win. I’m beginning to see why people just use bastion hosts.
Anyway, I might build sshca next ™️