Using SSH Certificates to Access Remote Machines

📘

Deeper Dive

For more in-depth information, check out our detailed documentation on the following topics:

How to Configure Keyless SSH
👍

Need any help?

If something in this tutorial isn't working as expected, feel free to contact our support team via Slack.

Below is a text-only guide for users based on the above video

SSH Certificates replace static SSH keys with short-lived certificates that Akeyless signs on request. Servers trust one Certificate Authority (CA) key instead of every user's public key.

This tutorial creates an SSH Signer Key and an SSH Certificate Issuer in Akeyless, sets a server to trust the signer key, then requests a certificate, logs in with it and watches it expire.

Prerequisites

  1. An Akeyless account with access to the Akeyless Console.
  2. The Akeyless CLI on the client machine, authenticated to your account.
  3. A target Linux server running OpenSSH, where you can edit sshd_config and restart the SSH service.

Set up Akeyless

Create the SSH Signer Key

In the Akeyless Console, go to Items > New > Encryption Key > DFC, and fill in:

Name: ssh-signer

Location: /demo/ssh-certificates

Click Next, and set:

Type: RSA2048. SSH certificates are signed with an RSA key.

Click Finish.

Copy the CA public key

Open ssh-signer and choose Get public RSA key. Copy the SSH-format key, the line that starts with ssh-rsa. The private key never leaves Akeyless.

Set up the target server

Trust the CA

On the target server, save the public key as /etc/ssh/ca.pub:

sudo nano /etc/ssh/ca.pub

Then, in /etc/ssh/sshd_config, point the TrustedUserCAKeys setting to that file:

sudo nano /etc/ssh/sshd_config
TrustedUserCAKeys /etc/ssh/ca.pub

Restart the SSH service

sudo systemctl restart ssh
cat ~/.ssh/authorized_keys

The file is empty. In a normal SSH key setup it would hold every user's public key. The server only trusts the CA.

Create the SSH Certificate Issuer

Name and signer key

Back in the Console, go to Items > New > SSH Cert Issuer, and fill in:

Name: ssh-issuer

Signer Key: /demo/ssh-certificates/ssh-signer

Settings

Certificate Lifetime in Seconds: 300. Every certificate expires after five minutes.

Allowed Users: ubuntu, the account on the server.

Principals: leave empty (optional).

Click Finish.

The issuer ssh-issuer is now listed next to ssh-signer.

❗️

Access method in production

The demo CLI uses an access key. In production, use a more secure auth method, like SSO or Cloud IAM, and let Akeyless access roles control who can request certificates.

Log in with a certificate

Request a certificate

On the client, which is the user logging into the server, run get-ssh-certificate with the username, the issuer and the path to your public key:

akeyless get-ssh-certificate \
  --cert-username ubuntu \
  --cert-issuer-name /demo/ssh-certificates/ssh-issuer \
  --public-key-file-path ~/.ssh/id_rsa.pub

Akeyless signs the key and saves the certificate next to it as id_rsa-cert.pub.

Inspect the certificate

ssh-keygen -L -f ~/.ssh/id_rsa-cert.pub | grep -A1 -E 'Valid|Principals'

The certificate is for the user ubuntu, and it is valid for five minutes.

Connect

ssh ubuntu@<server-ip>

You are logged into the server using only the certificate.

After it expires

Five minutes later, the same command is refused with Permission denied (publickey). There is nothing left to revoke.

The certificate expired on its own: no keys to copy, no keys to revoke.


Did this page help you?
Custom Footer Solution