Security & Monitoring

SSH keys off the disk: short-lived certificates for VPS

When a coding agent runs under your account, `~/.ssh` is within its reach: any private key without a passphrase is readable there, by the agent and by every script it launches. This guide offers three tiers to adopt one at a time: an encrypted key with `ssh-agent`, a FIDO2 hardware key, then short-lived SSH certificates signed by a certificate authority. You will see what each one stops, what it lets through, and how a collaborator leaving no longer forces you to touch client servers.

Deploy on a VPS Cloud →
10 min read9 steps
Contents· Why a key on disk is no longer enough1/12
  1. 01Why a key on disk is no longer enough
  2. 02What is within a coding agent's reach
  3. 03Tier 1: encrypted key, ssh-agent and confirmation on every use
  4. 04Tier 2: FIDO2 hardware key with ed25519-sk
  5. 05Tier 3: SSH certificates signed by a CA
  6. 06The three tiers side by side
  7. 07What this changes for an agency
  8. 08Keeping the CA without locking yourself out
  9. 09End-to-end test: certificate accepted, then refused
  10. 10Troubleshooting: the messages you will actually see
  11. 11The honest limit: what these tiers do not stop
  12. 12Where to check each option

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 ~/.ssh folder — 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_SOCK variable 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/config and known_hosts list 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

TierWhat it stopsWhat it lets through
1. Encrypted key and `ssh-add -c`Copying the key file, and silent use of the agent if you read every requestA 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 keyA security key lost without a backup key; a key that stays permanent on the servers
3. Certificate signed by a CAAccess forgotten after a departure: short validity, no `authorized_keys` to clean upA 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 -s accepts -D for a token and -U for 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 TrustedUserCAKeys file, 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 +8h makes 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

  1. 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_agence stays secret; only ca_agence.pub leaves the machine. For this test, a throwaway CA is enough.

  2. Prepare the collaborator's key

    On their workstation: ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_agence -C "alice@agence". Only id_agence.pub is handed to the CA. With an ed25519-sk key, you sign its public part the same way.

  3. Trust the CA on the VPS

    Copy ca_agence.pub to /etc/ssh/ca_agence.pub. In /etc/ssh/sshd_config, add TrustedUserCAKeys /etc/ssh/ca_agence.pub and AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u. Create /etc/ssh/auth_principals/deploy with the single line agence-ops. Here, %u becomes the name of the account being opened.

  4. Validate before reloading

    sudo sshd -t checks the syntax, then sudo systemctl reload ssh reloads the service, which is called sshd on AlmaLinux and Rocky. Keep your session open during the whole test: if something is wrong, you can roll back.

  5. Sign a two-minute certificate

    ssh-keygen -s ca_agence -I alice-portable -n agence-ops -V +2m ~/.ssh/id_agence.pub creates ~/.ssh/id_agence-cert.pub. In production, replace +2m with +8h.

  6. Reread the certificate

    ssh-keygen -L -f ~/.ssh/id_agence-cert.pub shows the identifier (Key ID), the principals and the Valid line, which gives the validity bounds. Check that the principal is agence-ops.

  7. 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 -v output shows an ED25519-CERT identity being offered, and the server log (journalctl -u ssh, with LogLevel VERBOSE) contains Accepted certificate ID "alice-portable".

  8. 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 line Certificate invalid: expired. No server file changed between the two attempts.

  9. Sign the working certificate

    Sign again with -V +8h for 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 with ssh -v to see the identities offered, then read the server log (journalctl -u ssh, with LogLevel 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 the ssh-add -c confirmation, or no prompt could appear for lack of ssh-askpass: install a confirmation program, then reload the key.
  • Certificate invalid: expired — the certificate is past the Valid bound that ssh-keygen -L displays: sign a new one. A Certificate invalid: not yet valid points instead to a skewed clock; -V -5m:+8h leaves a margin.
  • Certificate does not contain an authorized principal — none of the certificate's principals appears in /etc/ssh/auth_principals/<account>. Reread the -n option with ssh-keygen -L; a certificate signed without -n is 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, ssh sends only the configured identities: declare IdentityFile and CertificateFile together, or pass them with -i and -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

Share this articleservorbit.com/ma-en/blog/ssh-keys-off-disk-short-lived-certificates-vps

A root VPS to host your bastion and your CA

Prices shown excluding VAT, with their renewal price.