Why a key on disk is no longer enough
A coding agent started from your session inherits your rights: it reads your home directory, your environment variables and the socket of your SSH agent. A private key without a passphrase in ~/.ssh then has no protection of its own. A script it runs, a booby-trapped dependency or an instruction slipped into a repository is enough to copy it, as the guide on isolating coding agents describes. A recent Hacker News thread titled "Don't keep your SSH keys on disk" shows the topic is being debated; we take only that signal from it, none of its statements. For an agency, a second trigger comes on top: a collaborator leaving. Their key sits in authorized_keys on every client VPS, and you have to go through them one by one. The three tiers below answer both problems, and you can stop at the one that is enough for your team.
What is within a coding agent's reach
- The
~/.sshfolder — a private key without a passphrase is a file like any other; copying it takes one command line. - The SSH agent socket — the
SSH_AUTH_SOCKvariable points to a socket your account can open, so the coding agent can too: it requests signatures without ever reading the key. - The scripts and dependencies it launches — they run with your rights, not with its own.
- Your SSH configuration —
~/.ssh/configandknown_hostslist your client servers, that is, the targets. - Workstation backups — an unencrypted key leaves with every backup copy.
- Permanent access — a key published on a server stays valid until someone removes it, whether anyone leaves or not.
Tier 1: encrypted key, ssh-agent and confirmation on every use
Start by encrypting the key: ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_agence, with a real passphrase. The -a option sets the number of key derivation rounds, 32 by default according to the manual page. Then load the key with ssh-add -c ~/.ssh/id_agence: the -c option subjects each use to a confirmation, performed by ssh-askpass. AddKeysToAgent confirm in ~/.ssh/config has the same effect each time a key is added, and ssh-add -t 4h limits how long the key stays in the agent. This tier costs nothing and blocks copying the file at rest. It does not protect against a confirmation click given out of habit: the limit is detailed below. Load the key at the start of the day rather than leaving it in the agent permanently.
Tier 2: FIDO2 hardware key with ed25519-sk
An ed25519-sk key keeps the secret inside a FIDO2 security key; the file on disk is only a handle. With ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:agence -f ~/.ssh/id_agence_sk, each signature requires a touch on the key, and verify-required adds user verification, in practice the PIN. resident stores the handle on the key itself, and ssh-keygen -K downloads it on another workstation. The application string must begin with ssh:. Avoid no-touch-required, which removes the presence gesture altogether. On the server side, PubkeyAuthOptions verify-required in sshd_config refuses signatures without verification. Without the key plugged in and touched, nothing signs, even if the file is copied. Buy two keys from the start: the second one will be your backup.
Tier 3: SSH certificates signed by a CA
A certificate is your public key signed by a certificate authority (CA) the server knows. The server no longer keeps a list of keys: it checks the signature, the validity period and the allowed names. You sign with ssh-keygen -s ca_agence -I alice-portable -n agence-ops -V +8h id_agence.pub. The -I option sets the identifier that will appear in logs and can be used to revoke, -n lists the principals, -V sets the validity, here eight hours. The result is an id_agence-cert.pub file. On the server, TrustedUserCAKeys points to the CA public key, AuthorizedPrincipalsFile says which principals open which account, and RevokedKeys points to a list of keys or a KRL for emergencies. Without AuthorizedPrincipalsFile, the account name must appear in the certificate's principals. A certificate without a principal is refused.
The three tiers side by side
Scroll the table
| Tier | What it stops | What it lets through |
|---|---|---|
| 1. Encrypted key and `ssh-add -c` | Copying the key file, and silent use of the agent if you read every request | A confirmation approved out of reflex; a key that stays permanent on the servers |
| 2. `ed25519-sk` key with `verify-required` | Any signature without your presence and PIN; a useful copy of the key | A security key lost without a backup key; a key that stays permanent on the servers |
| 3. Certificate signed by a CA | Access forgotten after a departure: short validity, no `authorized_keys` to clean up | A stolen CA key; a signature obtained by an agent that reaches the CA |
What this changes for an agency
Without certificates, a collaborator leaving means removing their key from every client VPS, and a missed one stays open without anyone noticing. With a CA, you configure each server once: TrustedUserCAKeys and the principals file. After that, each collaborator receives an eight-hour certificate at the start of the day. When they leave, you stop signing, and their last certificate expires on its own: client servers receive no change. One principal per client, for example client-acme, also limits what each certificate opens. If the departure is urgent, add the certificate to the RevokedKeys list: that is the exception, not the routine. For the first connection to a new VPS, reread the first SSH login; for the shared entry point where this configuration belongs, see the bastion guide.
Keeping the CA without locking yourself out
- Offline CA key — store it on an unplugged encrypted medium, or in a PKCS#11 token:
ssh-keygen -saccepts-Dfor a token and-Ufor a key held by an agent. Never on the workstation where the coding agent runs. - A second, backup CA — generate two CAs, list both public keys in the
TrustedUserCAKeysfile, and keep the second one sealed and offline. Losing the first does not cut access. - A planned rotation — add the new public key to the file, sign with it, then remove the old one once the last certificates have expired. With eight hours of validity, the transition fits in a day.
- A tested emergency route — keep access through your provider's console or a dedicated emergency key, tried before you need it.
- Short validity —
-V +8hmakes revocation almost unnecessary: a stolen certificate is worth only a few hours. - Accurate clocks — validity is judged on the server's time and the workstation's; enable NTP synchronization everywhere.
End-to-end test: certificate accepted, then refused
Generate the CA, off the workstation
On a clean machine, ideally offline:
ssh-keygen -t ed25519 -f ca_agence -C "ca-agence", with a passphrase.ca_agencestays secret; onlyca_agence.publeaves the machine. For this test, a throwaway CA is enough.Prepare the collaborator's key
On their workstation:
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_agence -C "alice@agence". Onlyid_agence.pubis handed to the CA. With aned25519-skkey, you sign its public part the same way.Trust the CA on the VPS
Copy
ca_agence.pubto/etc/ssh/ca_agence.pub. In/etc/ssh/sshd_config, addTrustedUserCAKeys /etc/ssh/ca_agence.pubandAuthorizedPrincipalsFile /etc/ssh/auth_principals/%u. Create/etc/ssh/auth_principals/deploywith the single lineagence-ops. Here,%ubecomes the name of the account being opened.Validate before reloading
sudo sshd -tchecks the syntax, thensudo systemctl reload sshreloads the service, which is calledsshdon AlmaLinux and Rocky. Keep your session open during the whole test: if something is wrong, you can roll back.Sign a two-minute certificate
ssh-keygen -s ca_agence -I alice-portable -n agence-ops -V +2m ~/.ssh/id_agence.pubcreates~/.ssh/id_agence-cert.pub. In production, replace+2mwith+8h.Reread the certificate
ssh-keygen -L -f ~/.ssh/id_agence-cert.pubshows the identifier (Key ID), the principals and theValidline, which gives the validity bounds. Check that the principal isagence-ops.Connect with the certificate
ssh -v -i ~/.ssh/id_agence -o CertificateFile=~/.ssh/id_agence-cert.pub -o IdentitiesOnly=yes [email protected]. The connection opens; the-voutput shows anED25519-CERTidentity being offered, and the server log (journalctl -u ssh, withLogLevel VERBOSE) containsAccepted certificate ID "alice-portable".Wait for expiry, then retry
Wait more than two minutes and rerun the same command. The client answers
Permission denied (publickey), and the server log contains the lineCertificate invalid: expired. No server file changed between the two attempts.Sign the working certificate
Sign again with
-V +8hfor real use: access returns with no action on the VPS. That is the routine for a working day.
Troubleshooting: the messages you will actually see
Permission denied (publickey)— the client does not say why. Rerun withssh -vto see the identities offered, then read the server log (journalctl -u ssh, withLogLevel VERBOSE): the cause is written there.sign_and_send_pubkey: signing failed for ED25519 "…" from agent: agent refused operation— the agent refused to sign. You declined thessh-add -cconfirmation, or no prompt could appear for lack ofssh-askpass: install a confirmation program, then reload the key.Certificate invalid: expired— the certificate is past theValidbound thatssh-keygen -Ldisplays: sign a new one. ACertificate invalid: not yet validpoints instead to a skewed clock;-V -5m:+8hleaves a margin.Certificate does not contain an authorized principal— none of the certificate's principals appears in/etc/ssh/auth_principals/<account>. Reread the-noption withssh-keygen -L; a certificate signed without-nis refused outright.- Everyone is refused after adding
RevokedKeys— the manual page says it: if the file is not readable, public key authentication is refused for all users. Check the path and permissions before reloading. - The certificate is never offered — with
IdentitiesOnly yes,sshsends only the configured identities: declareIdentityFileandCertificateFiletogether, or pass them with-iand-o.
The honest limit: what these tiers do not stop
Encrypting the key and going through ssh-agent is not enough. A coding agent running under your account can open the socket named by SSH_AUTH_SOCK and request signatures as long as the key is loaded there: it does not need to read it. Only a gesture toward you blocks this silent use: the ssh-add -c confirmation, or the touch on the FIDO2 key. That gesture only counts if you read it; approved out of reflex, it no longer protects. A short-lived certificate limits the damage in time, it does not forbid use while it is valid. To go further, separate the roles: the coding agent on another machine or another server, as the guide on isolating agents explains.
Where to check each option
The options cited can be checked in the OpenSSH manual pages:
ssh-keygen · ssh-add
sshd_config · ssh_config
servorbit.com/ma-en/blog/ssh-keys-off-disk-short-lived-certificates-vps


