SSH has its own certificate format. It is not X.509: it is much simpler, has no ASN.1, no chains and no revocation hierarchy. A CA signs a user’s or host’s SSH public key and adds a name, a validity time and some restrictions.
This page is one continuous story with one set of names. We follow Alice, an engineer, who wants to log in to the server web01.example.com:
- Create the two CAs (one for users, one for hosts).
- Create Alice’s key, and have the user CA sign it: her certificate.
- Give the server a host certificate, and tell it to trust the user CA.
- Load Alice’s key and certificate into ssh-agent.
- Log in. Then see what the server logged, and what happens when it goes wrong.
All the output was captured by running these commands, including a real
sshd on a throwaway port.
id_ed25519 and, next to it, id_ed25519-cert.pub
automatically. Servers keep ssh_host_ed25519_key and
ssh_host_ed25519_key-cert.pub. We keep the two CA keys as user_ca and
host_ca. In real life user files live in ~/.ssh/; run the lab in an
empty directory instead, so you do not touch your real keys.The problem with plain SSH keys
Without certificates, SSH uses two lists of trust:
~/.ssh/authorized_keyson every server: which user keys may log in.~/.ssh/known_hostson every client: which host keys are genuine.
With 50 servers and 20 engineers, that is 1,000 key entries to add, audit and
remove. Nobody removes them. Leavers keep access. And the first connection to
a new host asks “are you sure you want to continue connecting?” and everyone
types yes.
The solution: an SSH CA
Servers trust one CA public key. The CA signs short-lived certificates.
| Without CA | With CA |
|---|---|
| Add each user key to each server | Servers trust the CA once |
| Keys live forever | Certificates last hours |
| Remove a leaver from every server | Do not renew; it expires |
| Trust On First Use for hosts | Hosts present a CA-signed host certificate |
Step 1: create the CAs
Use separate CA keys for users and for hosts. A user-CA key can then never be used to impersonate a server, and the other way round.
$ ssh-keygen -t ed25519 -N "" -C user-ca -f user_ca
$ ssh-keygen -t ed25519 -N "" -C host-ca -f host_ca
$ ls user_ca user_ca.pub host_ca host_ca.pub
host_ca host_ca.pub user_ca user_ca.pub
user_ca and host_ca are private and must be protected like any CA key
(see Protecting keys). The .pub files are public and
go to every server and client. (-N "" means “no passphrase”, acceptable for a
lab, not for a real CA.)
Step 2: Alice’s key, and her certificate
Alice creates her key pair. She sets a passphrase (the command asks for
it; the lab uses demo-pass):
$ ssh-keygen -t ed25519 -C alice@laptop -f id_ed25519
Enter passphrase (empty for no passphrase):
Only the public key, id_ed25519.pub, goes to the CA. The CA signs it
for 8 hours:
$ ssh-keygen -s user_ca -I alice-laptop -n alice,deploy -V +8h id_ed25519.pub
Signed user key id_ed25519-cert.pub: id "alice-laptop" serial 0 for alice,deploy
valid from 2026-11-25T11:53:00 to 2026-11-25T19:54:36
| Option | Meaning |
|---|---|
-s user_ca | Sign with this CA private key |
-I alice-laptop | Key ID: a label that shows up in server logs. Use the person’s identity |
-n alice,deploy | Principals: the account names the certificate may log in as |
-V +8h | Validity. Always short for users |
Read the certificate:
$ ssh-keygen -L -f id_ed25519-cert.pub
id_ed25519-cert.pub:
Type: ssh-ed25519-cert-v01@openssh.com user certificate
Public key: ED25519-CERT SHA256:PfnbQ55dOgNHca5ffUj8njNS2WasaxHNnTl8uuPvxko
Signing CA: ED25519 SHA256:lDST8q6PxyvyB4GENfIZX0v6AK9Hewz39eY1cYcXloo (using ssh-ed25519)
Key ID: "alice-laptop"
Serial: 0
Valid: from 2026-11-25T11:53:00 to 2026-11-25T19:54:36
Principals:
alice
deploy
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc
The Public key fingerprint is Alice’s key: the certificate wraps it. The
Signing CA fingerprint is user_ca: check it with ssh-keygen -lf user_ca.pub.
Restrict what a certificate allows
Critical options must be understood by the server or the certificate is
rejected. For example, a certificate for an automated job (a separate key,
ci_key) that can run only one command and only from the build network:
$ ssh-keygen -s user_ca -I ci-runner -n deploy \
-O clear -O force-command=/usr/bin/deploy -O source-address=10.0.0.0/8 \
-V +1h ci_key.pub
-O clear drops the default extensions (agent and X11 forwarding, and so on),
and you add back only what is needed.
Step 3: the server trusts the CA
On web01, one line in /etc/ssh/sshd_config replaces all the
authorized_keys files:
TrustedUserCAKeys /etc/ssh/user_ca.pub
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%u
user_ca.pub is the CA’s public key. The login name must appear in the
certificate’s principals. AuthorizedPrincipalsFile says which principals may
log in to which account: the file /etc/ssh/auth_principals/alice holds one
line, alice. (Without that line, only a principal equal to the account name
matches.) The principals file is where authorization lives, and you can map
for example a deploy principal to the account deploy.
Host certificates: end “are you sure?”
Sign the server’s host key, so clients can verify the server, using the host CA:
$ ssh-keygen -s host_ca -I web01 -h -n web01.example.com -V +52w ssh_host_ed25519_key.pub
Signed host key ssh_host_ed25519_key-cert.pub: id "web01" serial 0 for web01.example.com
valid from 2026-11-25T11:53:00 to 2027-11-24T11:54:24
$ ssh-keygen -L -f ssh_host_ed25519_key-cert.pub | sed -n 1,3p
ssh_host_ed25519_key-cert.pub:
Type: ssh-ed25519-cert-v01@openssh.com host certificate
Public key: ED25519-CERT SHA256:3E/ArYvZpoZdV06l2sid8UTBbPlkrdJVTeU9uhpI7Ic
On the server (sshd_config):
HostKey /etc/ssh/ssh_host_ed25519_key
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub
On every client, one line in ~/.ssh/known_hosts (or
/etc/ssh/ssh_known_hosts) trusts every host the host CA signs:
@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJhBuZt6V0...
Alice now never sees the “unknown host” question, and a stranger’s server
fails the check instead of getting a lazy yes.
Step 4: ssh-agent holds the unlocked key
A private key protected by a passphrase is good, but typing the passphrase
for every ssh, scp and git push is miserable, and people respond by
removing the passphrase. ssh-agent is the answer: a small background
program that holds your decrypted private keys in memory and signs on
behalf of ssh.
ssh ──"sign this challenge"──► ssh-agent (holds the unlocked key in memory)
▲ │
└──────────── signature ◄───────────┘
(the private key never leaves the agent)
- You start the agent once per login session.
- You add your key with
ssh-addand type the passphrase once. - When
sshconnects, the server sends a challenge.sshdoes not read your key file: it passes the challenge to the agent over a Unix socket, and the agent returns the signature. sshnever sees the private key, and the passphrase is not asked again.
ssh finds the agent through the environment variable SSH_AUTH_SOCK, which
holds the socket’s path. Most desktops start an agent for you at login (macOS
launchd, GNOME Keyring, the Windows OpenSSH Agent service). Check
echo $SSH_AUTH_SOCK before starting another one. To start one by hand:
$ eval "$(ssh-agent -s)"
Agent pid 50190
$ ssh-add -l
The agent has no identities.
Now add Alice’s key from Step 2, for the same 8 hours as her certificate:
$ ssh-add -t 8h id_ed25519
Enter passphrase for id_ed25519:
Identity added: id_ed25519 (alice@laptop)
Lifetime set to 28800 seconds
Certificate added: id_ed25519-cert.pub (alice-laptop)
Lifetime set to 28800 seconds
Notice the last two lines: ssh-add found id_ed25519-cert.pub next to the
key and loaded the certificate too, with no extra step. That naming
convention is why we used it. Look at what the agent holds:
$ ssh-add -l
256 SHA256:PfnbQ55dOgNHca5ffUj8njNS2WasaxHNnTl8uuPvxko alice@laptop (ED25519)
256 SHA256:PfnbQ55dOgNHca5ffUj8njNS2WasaxHNnTl8uuPvxko alice@laptop (ED25519-CERT)
$ ssh-add -L | cut -c1-60
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDp0t1h3UZSCQHA43uRajo3+m
ssh-ed25519-cert-v01@openssh.com AAAAIHNzaC1lZDI1NTE5LWNlcnQtdjAxQG9w
(-l prints fingerprints, -L full public keys.) Both lines have the same
fingerprint, matching the Public key line of the certificate in Step 2.
The certificate is the key plus the CA’s signature.
srw-------: only you (and root)
can talk to it. Whoever can use that socket can use your keys, so
protect it like the key itself.Step 5: log in
$ ssh alice@web01.example.com
alice@web01:~$
No password, no passphrase prompt, and no host-key question. What happened:
- The client checked
web01’s host certificate against@cert-authority. - The server saw a user certificate, checked the
user_casignature, the validity window and the principal. - The client asked the agent to sign the server’s challenge.
What the server logged
This is real output from the lab’s sshd (the account name is replaced by
alice). It is why we gave the certificate a meaningful Key ID:
Accepted certificate ID "alice-laptop" (serial 0) signed by ED25519 CA SHA256:lDST8q6PxyvyB4GENfIZX0v6AK9Hewz39eY1cYcXloo
Accepted publickey for alice from 127.0.0.1 port 56758 ssh2: ED25519-CERT SHA256:PfnbQ55dOgNHca5ffUj8njNS2WasaxHNnTl8uuPvxko ID alice-laptop (serial 0) CA ED25519 SHA256:lDST8q6PxyvyB4GENfIZX0v6AK9Hewz39eY1cYcXloo
The log line names the person (alice-laptop), the certificate serial
and which CA signed it. With plain keys you would only learn a key
fingerprint. This is your audit trail.
sshd listened on 127.0.0.1:2222 with the same
TrustedUserCAKeys, HostCertificate and principals file shown above,
and the client used -p 2222 and -o HostKeyAlias=web01.example.com
with a known_hosts containing the @cert-authority line. Everything
else is the same as on a real server.The agent really holds the key
To prove the agent does the signing, hide the private key file and log in again. It still works, because the agent has the key in memory:
$ mv id_ed25519 id_ed25519.hidden
$ ssh alice@web01.example.com 'echo still-ok'
still-ok
$ mv id_ed25519.hidden id_ed25519
When it goes wrong: the wrong principal
Suppose the CA signed Alice’s key for a different principal, mallory,
instead of alice:
$ ssh-keygen -s user_ca -I mallory-laptop -n mallory -V +1h id_ed25519.pub
The certificate is valid, and the CA is trusted, but the client gets:
$ ssh alice@web01.example.com
alice@web01.example.com: Permission denied (publickey).
and the server log says why:
Certificate does not contain an authorized principal
The client message is deliberately vague. Always read the server’s
sshd log (or ssh -vvv on the client) when a certificate login fails.
Everyday ssh-agent commands
| Command | What it does |
|---|---|
eval "$(ssh-agent -s)" | Start an agent and set SSH_AUTH_SOCK in this shell |
ssh-add ~/.ssh/id_ed25519 | Load a key (asks for the passphrase) |
ssh-add -t 8h ~/.ssh/id_ed25519 | Load it for 8 hours only |
ssh-add -c ~/.ssh/id_ed25519 | Ask for confirmation each time the key is used |
ssh-add -l / -L | List loaded keys (fingerprints / full public keys) |
ssh-add -d id_ed25519.pub | Remove one key |
ssh-add -D | Remove everything |
ssh-add -x / -X | Lock / unlock the whole agent with a password |
ssh-add -s /path/libpkcs11.so | Load keys from a smart card or HSM through PKCS#11 |
ssh-agent -k | Kill the agent |
Removing keys. The key and its certificate are two separate entries.
ssh-add -d id_ed25519.pub removes only the plain key; the certificate
stays loaded until you remove it as well (verified in the lab):
$ ssh-add -d id_ed25519.pub
Identity removed: id_ed25519.pub ED25519 (alice@laptop)
$ ssh-add -l
256 SHA256:PfnbQ55dOgNHca5ffUj8njNS2WasaxHNnTl8uuPvxko alice@laptop (ED25519-CERT)
$ ssh-add -d id_ed25519-cert.pub
Identity removed: id_ed25519-cert.pub ED25519-CERT (alice@laptop)
$ ssh-add -l
The agent has no identities.
Use ssh-add -D to clear everything at once.
Configure it in ~/.ssh/config
Host *.example.com
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
AddKeysToAgent 8h # load the key on first use, forget it after 8 hours
# macOS only: also remember the passphrase in the Keychain
UseKeychain yes
IdentitiesOnly yes makes ssh offer only the key named in IdentityFile
(and its -cert.pub), not every key in the agent.
ssh offers agent keys one by one, and servers hang up after about six
failed attempts: Too many authentication failures. Fix it with
IdentitiesOnly yes plus a specific IdentityFile per host.Short-lived certificates and the agent fit together
A login tool such as bxp-cli ssh signs you in
with SSO and writes a short-lived certificate next to your key
(id_ed25519-cert.pub, 8 hours by default). It does not touch the agent
itself. You then run:
$ bxp-cli ssh --key ~/.ssh/id_ed25519.pub
$ ssh-add -t 8h ~/.ssh/id_ed25519
ssh-add loads the key and the new certificate, with a lifetime equal to the
certificate’s. When it expires, the agent drops it and nothing is left to
steal. Result: no passwords typed, no long-lived access on disk, and a short,
auditable access window.
Agent forwarding: the dangerous part
ssh -A (or ForwardAgent yes) lets a remote server use your local
agent, so you can hop from web01 to db01 without copying keys onto web01.
It works by making a socket on web01 that tunnels back to your agent.
ForwardAgent yes under Host *.Alice’s certificate even says permit-agent-forwarding among its extensions
(Step 2). A stricter CA drops it with -O clear, and the CA decides, not the
user.
Safer alternatives:
| Instead of | Use |
|---|---|
ssh -A bastion.example.com then ssh web01.example.com | ssh -J bastion.example.com web01.example.com (ProxyJump): your client connects through the bastion and authenticates directly to web01, so no agent is exposed |
| One long-lived key for everything | Short-lived certificates, so a misused agent has a deadline |
| Silent signing | ssh-add -c (ask each time), or a hardware key that needs a touch (FIDO2 ed25519-sk keys) |
In ~/.ssh/config:
Host web01.example.com
ProxyJump bastion.example.com
Agent security summary
- The agent protects the key file (nobody can read it from disk or from backups) but not the use of the key while it is loaded. Malware running as you can use the agent.
- Use lifetimes (
-t), confirmation (-c) and hardware keys to limit that. - Do not forward the agent by default. Prefer
ProxyJump. - Lock the screen; run
ssh-add -Dbefore leaving a shared machine. - Make sure the socket directory is private (
0700). - For servers and CI, avoid long-lived agents with permanent keys. Give each
job its own short-lived certificate, like the
ci-runnerexample above.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
Could not open a connection to your authentication agent | No agent in this shell. Run eval "$(ssh-agent -s)" |
The agent has no identities. | Nothing loaded, or the lifetime expired. ssh-add again |
| Asks for the passphrase every time | Key not in the agent: use AddKeysToAgent or ssh-add |
Too many authentication failures | Too many keys offered. Use IdentitiesOnly yes |
Permission denied (publickey) with a certificate | Check the server log: Certificate does not contain an authorized principal (principal), Certificate invalid: expired, or the CA is not in TrustedUserCAKeys. Inspect with ssh-keygen -L -f id_ed25519-cert.pub and ssh -vvv |
| Host key warning with host certificates | Host cert expired or its principal does not match the name you typed (web01 vs web01.example.com), or @cert-authority pattern does not match |
Works locally, fails after ssh -A hop | Agent forwarding disabled on the server (AllowAgentForwarding no) |
X.509 vs SSH certificates
| X.509 | SSH | |
|---|---|---|
| Format | ASN.1 DER | Simple binary |
| Chains | Root, intermediates | One level: a certificate is signed directly by a CA key |
| Identity | Subject, SAN | Key ID, principals |
| Revocation | CRL, OCSP | Short validity; optional RevokedKeys file on servers |
| Used by | TLS, mTLS, S/MIME, code signing | OpenSSH only |
Operational advice
- Short validity (minutes to hours) for users. A stolen certificate is then nearly useless, and you almost never need revocation.
- Principals are your authorization. Mint them from a source of truth such as group membership in your IdP, not by hand. This is how role-based access with short-lived SSH certificates works in BastionXP.
- Issue only after the user authenticates with SSO and MFA (OIDC), so the certificate is proof of a fresh login.
- Protect the CA keys (
user_ca,host_ca) like any CA key: HSM or KMS. - Keep Key IDs meaningful (
alice-laptop); they appear insshdlogs and are your audit trail. - Use separate CA keys for users and hosts, as in Step 1.
- Directory users on Linux: see LDAP and Active Directory for how accounts and groups reach the server.
See BastionXP SSH Certificate Management.
Related articles
- What is an SSH Agent and How it works
- How to Create a New SSH Key Using ssh-keygen
- How to configure and setup SSH certificates for SSH authentication
- How to create and manage short-lived SSH public keys
- SSH Key Management Tools and Best Practices
About BastionXP
BastionXP is a cloud-native private PKI CA and device identity management platform that eliminates passwords and shared secrets by issuing hardware-attested certificates to mobile devices and laptops. Secure access to your Wi-Fi, VPN, and SaaS applications in your enterprise network. Replace legacy SCEP with automated ACME Device Attestation. No shared secrets. Zero credential theft. Learn more about BastionXP →