Select Page

SSH vs X.509 Certificates – DZone Security

Linda Ikechukwu
Published: November 2, 2022

As a developer or systems administrator, you’re probably used to SSHing into servers with key pairs. What if I told you there is a better and more secure way to manage SSH access? Think SSH certificates (And no, they’re not the same as TLS certificates)

For most people, their knowledge of certificates lies within the confines of the X.509 digital certificates format — also known as TLS/SSL certificates — used by browsers to enable HTTPS. However, the X.509 certificate is not the only digital certificate format that exists; there is also the less-popular SSH certificate format created by OpenSSH.

While X.509 certificates enable identity authentication for browser-to-server communication, SSH certificates enable identity authentication for shell(terminal) to *nix server communications. This article will briefly discuss what SSH certificates are, why you should be using them, and the key distinctions between them and X.509 certificates.

What Are SSH Certificates?

When decoded, an OpenSSH certificate is just a data structure containing a public key, name, and optional information like an expiration date and associated permissions. SSH certificates are much like X.509 certificates but with fewer properties.

An OpenSSH certificate is the most secure way of granting SSH access. Yet, it’s not widely utilized, likely due to developers simply not knowing about it. It also requires more up-front work than a typical SSH public/private key setup, which most people are wary of. However, once implemented, the benefits outweigh the trouble, especially when you have a lot of users, hosts, and keys to manage.

SSH Authentication Without Certificates

Despite the release of SSH certificate-based authentication by OpenSSH in 2010, most people still carry out SSH authentication with passwords or public keys.

Password-based SSH authentication has long been criticized since humans are prone to using unavoidably predictable and weak passwords that are easy to hack. A 2019 Avast survey found that over 80% of average Americans use weak passwords. Additionally, passwords are directly transmitted to the server during an SSH connection initiation, thus making it vulnerable to brute-force attacks.

SSH Public key authentication provides a more secure alternative to passwords, but it is still easily misused. With public key authentication, all clients and servers must have their own public and private key pairs. When a client machine tries to initiate an SSH connection to a server, two things happen:

  1. The client will try to confirm that it’s connecting to a trusted server by checking if the server’s public key is in its known_hosts file. If the client does not recognize the server’s public key, it throws an error (as shown) saying that the server’s authenticity can’t be proven but asking if it should connect anyway:

    The authenticity of host 'xxx' can't be established.
    RSA key fingerprint is SHA256:kfcwi9X8T4nMRw1OM0xDXETGcqjU26/zbM+KqNB6CKw.
    Are you sure you want to continue connecting (yes/no)?

  2. The server will also try to authenticate the user by checking if the user’s public key is present in its authorized_keysfile. Typically, team members send off their public key to an administrator for it to be added or deployed to the authorized_keysfile of every server they need access to. What happens when there are > 10s of servers to which these keys need to be deployed? This presents the second flaw of public-key-based SSH authentication: key management can easily become tedious and time-wasting and is not scalable for large organizations.

Finally, because keys never expire, SSH public key authentication exposes systems to security vulnerabilities. For example, when a developer leaves a company, their public key is supposed to be deleted from all hosts… but we all know in practice that just isn’t the case. SSH academy recounts that in an analysis of 15000 servers, out of the three million SSH keys that granted access to live production servers, 90% were no longer used. Such compromised key bindings can go unnoticed for a long time, exposing the system to unauthorized access.

Some commercial and open-source services try to help tackle these key management crises. The basic idea is that you maintain keys through that service, and when you remove a key, they will remove it from all your servers. However, the danger is that the service could become a single point of failure. If an attacker captures access to that service, they can access all your servers. And in the worst-case scenario, if you lose access to that service, you will also lose access to all your servers.

SSH Authentication With Certificates

SSH certificate-based authentication works similarly to X.509 certificates but with a considerably simpler implementation. With SSH certificate-based authentication, clients and hosts mutually authenticate each other, thereby eliminating TOFU.

First, set up an SSH CA server (aka an “online CA”) that will house two SSH CA key pairs: a host CA key pair for signing and authenticating certificates for host machines and a user CA key pair for signing and authenticating certificates for clients. For SSH, people use the term CA (certificate authority) to interchangeably refer both to the signing key pairs and the SSH CA server.

It’s best practice to create two separate CA key pairs to reduce the attack surface. If a private key is compromised, you only need to reissue the certificates for your hosts or users, not both at once.

After you generate the host CA and user CA key pairs, configure all host machines to trust certificates signed by the public key of the user CA. You will also need to configure all clients to trust certificates signed by the public key of the host CA.

To issue certificates with hosting machines, you’ll have to generate public-private key pairs for all host servers and sign them with the host CA keys. To issue client (user) certificates, You’ll also need to generate key pairs for all clients and sign them with the user CA keys. Ideally, the process of issuing user certificates is completely automated. For example, you could build a flow where users can automatically get signed certificates when they authenticate with your company’s identity provider.

When a client wants to access a host, it’ll present its certificate to the host, and the host will do the same. Host servers will only allow access to clients with certificates trusted by keys, and clients can rest assured that they’re connecting to a trusted host.

Granted, this is a bit of an oversimplification of the actual process. If you are looking for a practical walk-through of the process described above, you can check out our docs on Working with SSH Certificates.

Apart from eliminating mundane key management tasks and TOFU, SSH certificate-based authentication also offers some features which allow for fine-grained access:

  • Certificates expire. Users can be issued short-lived certificates to eliminate the risk of abandoned compromised key bindings. For example, if a developer leaves without having their access revoked, their certificate will expire after a certain period of time, and they will also lose access automatically.
  • Certificates are restricted to certain users (principals). This creates an opportunity to enable role-based access control.
  • Certificates can contain SSH restrictions, e.g., forbidding PTY allocation or port forwarding.

How Are SSH Certificates Different From X.509 Certificates?

Now that we understand what SSH certificates are and how they are used let’s look at how they differ from X.509 certificates.

Use Cases

X.509 certificates are designed to be ubiquitous. They can be used in SSL/TLS, S/MIME, EAP-TLS, and even in the SSH protocol for web applications, databases, VPNs, WiFi, digital signatures for document signing, and all kinds of other places. SSH certs are mainly used for SSH access and authentication.


In OpenSSH, SSH certs are much simpler and have only a few features. Unlike traditional X.509 certificates, with numerous options and complex encoding rules, the SSH certificate is just public and private key pairs with additional identity and constraints data.

Here’s what a decoded SSH user certificate and X.509 client certificate look like:

$ step ssh inspect
        Type: user certificate
        Public key: ECDSA-CERT SHA256:O6M6oIjDm5gPm1/aTY619BgC3KSpS4c3aHVWxYh/uGQ
        Signing CA: ECDSA SHA256:EY2EXJGoPv2LA6yEbjH+sf9JjG9Rd45FH1Wt/6H1k7Y
        Key ID: ""
        Serial: 4309995459650363134
        Valid: from 2022-07-11T14:50:01 to 2022-07-11T18:50:01
        Critical Options: (none)

step certificate inspect
        Version: 3 (0x2)
        Serial Number: 312048233971325841563421249287934957707544 (0x39506ffca33cfa15b5325cace3c6c45e118)
    Signature Algorithm: SHA256-RSA
        Issuer: C=US,O=Let's Encrypt,CN=R3
            Not Before: Jun 6 07:05:01 2022 UTC
            Not After : Sep 4 07:05:00 2022 UTC
        Subject: CN=*
        Subject Public Key Info:
            Public Key Algorithm: ECDSA
                Public-Key: (256 bit)
                Curve: P-256
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature
            X509v3 Extended Key Usage:
                Server Authentication, Client Authentication
            X509v3 Basic Constraints: critical
            X509v3 Subject Key Identifier:
            X509v3 Authority Key Identifier:
            Authority Information Access:
                OCSP - URI:
                CA Issuers - URI:
            X509v3 Subject Alternative Name:
            X509v3 Certificate Policies:
            RFC6962 Certificate Transparency SCT:
                SCT [0]:
                    Version: V1 (0x0)
                    LogID: QcjKsd8iRkoQxqE6CUKHXk4xixsD6+tLx2jwkGKWBvY=
                    Timestamp: Jun 6 08:05:01.371 2022 UTC
                    Signature Algorithm: SHA256-ECDSA
                SCT [1]:
                    Version: V1 (0x0)
                    LogID: RqVV63X6kSAwtaKJafTzfREsQXS+/Um4havy/HD+bUc=
                    Timestamp: Jun 6 08:05:01.416 2022 UTC
                    Signature Algorithm: SHA256-ECDSA
    Signature Algorithm: SHA256-RSA


In X.509 implementation, certificate authorities always have their own certificates and can have intermediate certificate authorities (certificate chaining). SSH does not allow all that. Following a more simplistic approach allows SSH certificate configuration to be easier and minimizes the attack surface.

Also, there are two SSH certificate formats: host certificate and user certificate. In X.509, you specify whether a certificate allows for “server authentication” or “client authentication” (a single X.509 certificate can allow for both)

Can You Use an X.509 CA to Issue SSH Certificates?

No. To support SSH certificate-based authentication, you will need to maintain another CA that can handle SSH certificate signing and issuance because OpenSSH uses a custom (simpler) certificate format.

SSH Certificates Are the Right Way to Do SSH

OpenSSH certificates have a lot of power to them. They allow you to drop complex key approval & distribution processes. They also offer ephemeral SSH access, making key management oversights fail-secure. You should be using them if you’re not already!