OpenSSH Certificate Cheatsheet
A practical reference for creating, signing, configuring and troubleshooting OpenSSH certificates using ssh-keygen, ssh and sshd.
OpenSSH certificates allow SSH clients and servers to establish trust through certificate authorities rather than distributing and maintaining individual trusted public keys.
This cheatsheet covers user certificates, host certificates, certificate principals, validity periods, revocation and common authentication problems.
New to SSH certificate authentication? Read our Complete Guide to OpenSSH Certificates for an explanation of certificate authorities, trust relationships and how certificate authentication works.
All examples use Ed25519 keys and standard OpenSSH tools unless otherwise stated.
Commands are intended for Unix-like environments with a compatible OpenSSH installation. File paths and account names are illustrative and should be adapted to your environment.
In this guide
Quick Reference
| Task | Command or Configuration |
|---|---|
| Generate CA | ssh-keygen -t ed25519 -f user_ca |
| Generate user key | ssh-keygen -t ed25519 -f user_key |
| Sign user key | ssh-keygen -s user_ca -I alice -n alice -V +1h user_key.pub |
| Sign host key | ssh-keygen -s host_ca -I server01 -h -n server.example.com -V +52w ssh_host_ed25519_key.pub |
| Inspect certificate | ssh-keygen -Lf user_key-cert.pub |
| Inspect CA public key | ssh-keygen -lf user_ca.pub |
| Connect with certificate | ssh -i user_key alice@server.example.com |
| Debug authentication | ssh -vvv -i user_key alice@server.example.com |
| Generate a KRL | ssh-keygen -k -f revoked_keys.krl user_key-cert.pub |
| Check KRL | ssh-keygen -Q -f revoked_keys.krl user_key-cert.pub |
Generate User Keys
Generate an Ed25519 key pair for a user:
ssh-keygen -t ed25519 -f user_key -C "alice@example.com"Creates:
user_key
user_key.pubThe private key remains with the user.
Only the public key is submitted to the CA for signing.
The CA does not need access to the user's private key.
Sign User Certificates
Basic User Certificate
ssh-keygen -s user_ca \
-I alice-001 \
-n alice \
-V +1h \
user_key.pubThis creates:
user_key-cert.pubOptions:
| Option | Meaning |
|---|---|
| -s user_ca | CA private key used to sign |
| -I alice-001 | Certificate key identifier |
| -n alice | Valid principal |
| -V +1h | Valid from now for one hour |
| user_key.pub | Public key to certify |
Sign for Multiple Principals
ssh-keygen -s user_ca \
-I alice-002 \
-n alice,deploy,readonly \
-V +1h \
user_key.pubThe certificate contains three principals:
alice
deploy
readonlyThe target server determines which principals are authorized for the account being accessed.
A principal appearing in the certificate does not automatically grant access to a corresponding operating system account.
Sign with a Serial Number
ssh-keygen -s user_ca \
-I alice-003 \
-z 1001 \
-n alice \
-V +1h \
user_key.pubThe -z option sets the certificate serial number.
Serial numbers can support issuance tracking and certificate revocation.
Use a controlled, unique serial allocation process for certificates issued by the same CA.
Restrict Source Addresses
ssh-keygen -s user_ca \
-I alice-office \
-n alice \
-V +1h \
-O source-address=192.0.2.0/24 \
user_key.pubThe source-address critical option restricts the client source addresses from which the certificate may be accepted.
This is an additional restriction, not a replacement for network security controls.
Disable PTY Allocation
ssh-keygen -s user_ca \
-I alice-no-pty \
-n alice \
-V +1h \
-O clear \
-O permit-port-forwarding \
user_key.pub-O clear removes the default certificate permissions.
The example then selectively restores port forwarding without permitting PTY allocation.
Certificate extensions interact with server configuration. An extension permitting a feature does not override a server-side restriction that disables it.
Configure SSH Servers
Install the Trusted User CA
Copy the CA public key to the server:
sudo install -m 0644 user_ca.pub /etc/ssh/user_ca.pubConfigure /etc/ssh/sshd_config:
TrustedUserCAKeys /etc/ssh/user_ca.pubThis tells OpenSSH to trust user certificates signed by the specified CA.
It does not automatically authorize every principal or account.
Validate Configuration
sudo sshd -tIf validation succeeds, reload the SSH service using the appropriate command for the operating system.
For example, on systems using a service named sshd:
sudo systemctl reload sshdOn systems where the service is named ssh, use the corresponding service name.
Do not close an existing administrative session until certificate authentication has been tested successfully.
Certificate Principals
Principals define identities or roles that a certificate may represent.
The server must determine whether a certificate principal is authorized for the target account.
Configure an Authorized Principals File
In sshd_config:
TrustedUserCAKeys /etc/ssh/user_ca.pub
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%uFor the local account deploy, create:
/etc/ssh/auth_principals/deployExample contents:
production-deploy
release-engineerA certificate containing either authorized principal may satisfy this part of the authorization policy for the deploy account, subject to the remaining SSH authentication checks and restrictions.
Sign a Certificate for a Role
ssh-keygen -s user_ca \
-I alice-deploy \
-n production-deploy \
-V +15m \
user_key.pubThe user can attempt to connect as:
ssh -i user_key deploy@server.example.comThe server evaluates whether the production-deploy principal is authorized for the deploy account.
Dynamic Principal Authorization
OpenSSH also supports AuthorizedPrincipalsCommand.
This allows authorized principals to be obtained through an external command rather than a static file.
The command and its execution identity must be configured securely.
Dynamic authorization can support integration with centralized identity and access management systems.
Connect Using Certificates
Automatic Certificate Discovery
If the private key is:
~/.ssh/user_keyAnd the certificate is:
~/.ssh/user_key-cert.pubOpenSSH normally discovers the certificate automatically when the corresponding identity is used.
Connect with:
ssh -i ~/.ssh/user_key alice@server.example.comExplicit Certificate Configuration
Add to ~/.ssh/config:
Host production
HostName server.example.com
User deploy
IdentityFile ~/.ssh/user_key
CertificateFile ~/.ssh/user_key-cert.pub
IdentitiesOnly yesConnect with:
ssh productionDebug Certificate Authentication
ssh -vvv -i ~/.ssh/user_key deploy@server.example.comVerbose output helps identify which identities and certificates the client offers and how authentication proceeds.
Host Certificates
Host certificates allow SSH clients to authenticate servers through a trusted host CA.
This is particularly useful when servers are frequently provisioned or replaced.
Generate a Host CA
ssh-keygen -t ed25519 -f host_ca -C "SSH Host CA"Sign a Host Public Key
ssh-keygen -s host_ca \
-I server01 \
-h \
-n server.example.com,server01.example.com \
-V +52w \
ssh_host_ed25519_key.pubThe -h option specifies a host certificate.
The -n option defines valid hostnames or host identities.
The validity period is illustrative. Production host certificate lifetimes should reflect the organization's issuance and renewal capabilities.
Configure the SSH Server
In sshd_config:
HostKey /etc/ssh/ssh_host_ed25519_key
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pubThe host certificate must correspond to the configured host private key.
Trust the Host CA on Clients
Add an entry to the client's known_hosts file:
@cert-authority *.example.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI...Replace the abbreviated public key with the complete contents of host_ca.pub.
The hostname pattern defines where the CA is trusted.
The CA key should be distributed through a trusted administrative process.
Do not disable SSH host verification as a substitute for configuring host CA trust.
Inspect Certificates
Display Certificate Details
ssh-keygen -Lf user_key-cert.pubThe output includes information such as:
- Certificate type.
- Signing CA.
- Key identifier.
- Serial number.
- Valid principals.
- Validity interval.
- Critical options.
- Extensions.
Inspect a Host Certificate
ssh-keygen -Lf ssh_host_ed25519_key-cert.pubDisplay a Public Key Fingerprint
ssh-keygen -lf user_key.pubDisplay a Certificate Fingerprint
ssh-keygen -lf user_key-cert.pubCertificate inspection is useful when diagnosing principal mismatches, expired credentials and unexpected certificate options.
Certificate Validity
OpenSSH certificates include a validity interval.
The -V option controls when the certificate becomes valid and when it expires.
Fifteen-Minute Certificate
ssh-keygen -s user_ca -I short-lived -n alice -V +15m user_key.pubOne-Hour Certificate
ssh-keygen -s user_ca -I hourly -n alice -V +1h user_key.pubOne-Day Certificate
ssh-keygen -s user_ca -I daily -n alice -V +1d user_key.pubExplicit Validity Window
ssh-keygen -s user_ca \
-I scheduled \
-n alice \
-V 20261023090000:20261023170000 \
user_key.pubThe explicit timestamps above are illustrative.
OpenSSH interprets these timestamps according to the signing environment's time settings.
Validity and Existing Sessions
Certificate expiration prevents the certificate from being accepted for new authentication after its validity period.
It does not automatically terminate SSH sessions that were established while the certificate was valid.
Organizations requiring immediate session termination must implement additional controls.
Clock Synchronization
Certificate validation depends on time.
Ensure clients, servers and certificate issuance systems maintain reliable clock synchronization.
Significant clock differences can cause otherwise legitimate certificates to be rejected.
Certificate Revocation
OpenSSH supports Key Revocation Lists, or KRLs.
KRLs can identify public keys and certificates that should no longer be accepted.
Create a Revocation List
ssh-keygen -k -f revoked_keys.krl user_key-cert.pubThis creates a KRL containing a revocation for the specified certificate.
Check Whether a Certificate Is Revoked
ssh-keygen -Q -f revoked_keys.krl user_key-cert.pubThe command reports whether the supplied certificate is revoked by the KRL.
Configure Server-Side Revocation
In sshd_config:
RevokedKeys /etc/ssh/revoked_keys.krlThe revocation file must be readable by the SSH daemon.
If the configured revocation file cannot be read, OpenSSH may refuse public-key authentication.
Revocation at Scale
A KRL must be distributed to the systems expected to enforce it.
Short-lived certificates reduce the period during which compromised credentials remain usable for new authentication, but they do not provide immediate revocation.
For production deployments, establish a clear process for revoking certificates, updating authorization and responding to compromised CA keys.
Troubleshooting OpenSSH Certificates
Permission Denied (publickey)
Possible causes:
- The server does not trust the issuing CA.
- The certificate has expired or is not yet valid.
- The certificate principal is not authorized.
- The client is not presenting the expected certificate.
- The private key does not match the certificate.
- Server configuration or file permissions prevent authentication.
- A certificate restriction or server policy rejects the connection.
Start with:
ssh -vvv -i user_key alice@server.example.comThen inspect the certificate:
ssh-keygen -Lf user_key-cert.pubCertificate Is Not Offered
Confirm that the certificate filename matches the private key filename with the -cert.pub suffix.
Alternatively, configure CertificateFile explicitly.
Inspect effective client configuration with:
ssh -G server.example.comCertificate Principal Not Authorized
Inspect the certificate:
ssh-keygen -Lf user_key-cert.pubCheck the server's AuthorizedPrincipalsFile, AuthorizedPrincipalsCommand or applicable account principal-matching configuration.
The certificate principal must be acceptable for the account being accessed.
Certificate Expired
Inspect the validity interval:
ssh-keygen -Lf user_key-cert.pubRequest or issue a new certificate after performing the appropriate identity and authorization checks.
Do not simply increase certificate lifetimes to avoid implementing renewal.
Unknown Certificate Authority
Verify that the server trusts the correct user CA public key.
Check:
TrustedUserCAKeysFor host certificates, verify that the client trusts the correct host CA through its known_hosts configuration.
Host Certificate Rejected
Check:
- Host certificate validity.
- Hostname principals.
- Trusted host CA.
- Host certificate and private key correspondence.
- Host certificate configuration on the server.
Use verbose client diagnostics:
ssh -vvv server.example.comServer-Side Diagnostics
Inspect SSH server logs using the operating system's logging facilities.
On a system using systemd and a service named sshd:
sudo journalctl -u sshdService names and logging locations vary by operating system.
For advanced troubleshooting, use an isolated test SSH daemon with an appropriate debug configuration rather than disrupting a production SSH service.
ssh-keygen Certificate Options Reference
| Option | Purpose |
|---|---|
| -s | Specify the CA private key for signing |
| -I | Set the certificate key identifier |
| -n | Set valid certificate principals |
| -V | Set the certificate validity interval |
| -z | Set the certificate serial number |
| -h | Create a host certificate |
| -O | Specify certificate options or extensions |
| -L | Display certificate information when used with -f |
| -k | Generate a Key Revocation List |
| -Q | Test whether keys or certificates are revoked by a KRL |
| -f | Specify the relevant key, certificate or KRL file, depending on the operation |
Common Certificate Options
| Option | Description |
|---|---|
| clear | Remove default certificate permissions |
| force-command=... | Restrict execution to a specified command |
| source-address=... | Restrict acceptable client source addresses |
| permit-pty | Permit PTY allocation |
| permit-port-forwarding | Permit port forwarding |
| permit-agent-forwarding | Permit agent forwarding |
| permit-X11-forwarding | Permit X11 forwarding |
| permit-user-rc | Permit execution of user RC files |
| no-touch-required | Relax touch requirements for applicable FIDO authenticator-backed keys |
| verify-required | Require user verification for applicable FIDO authenticator-backed keys |
Certificate permissions and server configuration are evaluated together.
A certificate extension does not override a server-side restriction.
Consult the installed OpenSSH manual for options supported by the deployed version.
Production Best Practices
OpenSSH certificates provide a strong foundation for scalable SSH authentication, but secure deployment requires more than generating a CA key pair.
Protect CA private keys. Restrict access to signing keys, separate duties where appropriate and consider hardware-backed or managed signing infrastructure.
Separate user and host authorities. Use distinct CA keys for the different trust relationships.
Prefer short-lived user certificates. Reduce the lifetime of credentials and automate issuance where practical.
Authenticate before issuing. Verify the identity of the requesting user or workload.
Authorize every issuance. Determine which principals and permissions are appropriate before signing.
Use explicit principals. Avoid issuing unnecessarily broad certificates.
Track issuance. Record key identifiers, serial numbers, principals, validity periods and relevant issuance decisions.
Plan for revocation. Define how compromised certificates, keys and authorities will be handled.
Secure client private keys. Certificate authentication still relies on proof of possession of the corresponding private key.
Test configuration changes. Validate server configuration and maintain an administrative recovery path.
Avoid permanent manual signing workflows. Short-lived certificates are most useful when issuance and renewal are integrated with identity and access management.
Managing Certificates at Scale
The commands in this cheatsheet demonstrate the native OpenSSH certificate mechanisms.
For small environments, manual certificate signing may be sufficient.
At larger scales, the challenge shifts from cryptography to operations: authenticating users, approving access, issuing certificates, maintaining policy and handling credential lifecycle events.
SSH Teams builds on OpenSSH certificate authentication to provide managed, short-lived SSH access using existing SSH clients and servers.
It is designed to reduce reliance on permanently authorized individual SSH keys without requiring a proprietary SSH protocol or mandatory bastion host.
Explore SSH Teams
Further Reading
OpenSSH Certificates: The Complete Guide to SSH Certificate Authentication
Understand the OpenSSH certificate trust model, certificate authorities, user and host certificates, principals, short-lived credentials and certificate management.
OpenSSH Manual Pages
Consult the official OpenSSH documentation for version-specific options and configuration behavior.
ssh-keygen(1)ssh(1)ssh_config(5)sshd_config(5)