Strovent SystemsSign in
Reference

OpenSSH certificates

How a certificate authority signs SSH keys, what a user certificate contains, and how to make one.

An OpenSSH certificate is a public key that a CA (certificate authority) has signed. It is not an X.509 certificate. Hosts that trust the CA accept the certificate without needing your key listed in authorized_keys.

Two kinds

  • User certificate. Proves you to a host. The host trusts the CA through TrustedUserCAKeys in sshd_config.
  • Host certificate. Proves a host to you. The client trusts the CA through a @cert-authority line in known_hosts, so there is no first-connection prompt. See SSH host certificates and @cert-authority in known_hosts.

What a user certificate contains

  • The public key it is for.
  • A key ID (any name, written to the host's logs).
  • The principals: the user names it may log in as.
  • A validity period: a start and an end time.
  • Extensions and options: for example permit a PTY, or limit the source address.

Why use them

  • Short-lived access. A certificate valid for hours or a week expires on its own.
  • No authorized_keys to maintain on every host.
  • One place (the CA) to control who may log in.

Making one

ssh-keygen -s ca_key -I jsmith -n jsmith -V +52w id_ed25519.pub

This writes id_ed25519-cert.pub next to the public key. The certificate line starts with the type, for example [email protected].

To use it, put the certificate next to the private key (a client picks it up by the -cert.pub name) or load both into the agent.

On the host

TrustedUserCAKeys /etc/ssh/ca.pub
AuthorizedPrincipalsFile /etc/ssh/principals/%u

Common problems

  • Expired or not yet valid. Check the dates and the clock of both machines.
  • Principal not allowed. The user name you log in as must be in the certificate's principals, or in the host's principals file.
  • Wrong key. A certificate only works with the private key it was made for.
  • Host certificate pasted as a user certificate. ssh-keygen -L -f cert.pub shows the type, principals and validity.

Spotted a mistake? Email [email protected].