SSH CA - Getting Started¶
BastionXP SSH Certificate Manager¶
Follow the steps below to download, install and run BastionXP as a standalone SSH Certificate Manager in your self-hosted server on-prem.
Prerequisites¶
You need to have the following to install and run BastionXP Certificate Manager: - A Linux VM or server (Debian or RHEL or Any Linux distribution) - TCP Port: 443
BastionXP SSH CA VM Setup¶
Step 1.1 - Download and Install¶
On the Linux VM, follow the instructions here to download and install the appropriate BastionXP binary package for your Linux distro as RPM or Debian package.
BastionXP will be installed as a Linux Systemd service. It runs as root, and keeps its data in /var/lib/bastionxp.
Step 1.2 - The Server's Certificate¶
BastionXP serves its web portal and its API over HTTPS. For this, it needs a certificate and a private key, which you provide. BastionXP never creates its own HTTPS certificate.
Put the certificate and its private key in BastionXP's data directory, with these names:
In production, the certificate must be for BastionXP's domain name, for example ca.example.com. You can get it from your company's PKI or from a public CA. Or BastionXP can get one from Let's Encrypt by itself. See Configuration.
This guide runs BastionXP on localhost. So create a self-signed certificate for localhost, and make this machine trust it:
sudo openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 365 \
-subj /CN=localhost -addext subjectAltName=DNS:localhost \
-keyout /var/lib/bastionxp/server.key -out /var/lib/bastionxp/server.crt
sudo chmod 600 /var/lib/bastionxp/server.key
sudo cp /var/lib/bastionxp/server.crt /usr/local/share/ca-certificates/bastionxp-localhost.crt
sudo update-ca-certificates
Step 1.3 - The Key-Encryption Key¶
BastionXP keeps the private keys of its CAs in its database, and it encrypts them there. The key that encrypts them is called the key-encryption key (KEK). The KEK is kept in a file outside the database.
Create the KEK once:
$ sudo mkdir -p /etc/bastionxp
$ sudo bastionxp kek create --out /etc/bastionxp/kek
KEK: /etc/bastionxp/kek
KEK id: 90e1fbc8cfcbe55a
Back it up now, separately from the database: in a password manager or a
safe, never next to the database backups. Losing the KEK means losing every
certificate authority. Every BastionXP server needs the same KEK.
See Key protection for more.
Step 1.4 - Configuration File¶
Create a configuration file named config.yaml in the /etc/bastionxp directory, with the following contents.
email: [email protected]
domain: localhost
org_name: Example Corporation
kek_file: /etc/bastionxp/kek
emailis the email address of the web portal's first administrator.domainis the DNS name of your BastionXP server.org_nameis the name of your organization. BastionXP writes it into the certificates that it issues.kek_fileis the path of the KEK that you created in step 1.3.
See Configuration for all the settings.
Step 1.5 - Restart¶
The package starts BastionXP when you install it. At that time, there was no configuration file yet, so BastionXP could not start. Restart it now, so that it reads the configuration file.
BastionXP writes its log to the system journal. Read it with:
You will see log lines like these. This is a shortened example.
level=INFO msg="key-encryption key loaded" kek_id=90e1fbc8cfcbe55a
level=INFO msg="primary admin created" [email protected]
level=WARN msg="the primary admin has no password yet: open this link to set it, and a second factor" [email protected] link="https://localhost/#/setup?token=0xKz30j3DjUeEUyEYOgWPzIzaztkhpCPh-02HfC2V0A" expires=2026-11-29T06:14:27Z
level=INFO msg="server started" address=:443 authorities=[]
The line with link= is important. It is the one-time link that you use in the next step to set up the administrator account.
If BastionXP does not start, the log tells you why. For example, the message may say that server.crt or the KEK is missing, or that a setting in config.yaml is misspelled.
Step 1.6 - Set up the Administrator Account¶
The first administrator has no default password. Instead, you use the one-time setup link from the log.
-
Open the setup link in your browser. The link works once, and it is valid for 24 hours.
If the link has expired, or if you cannot find it, make a new one with this command:
-
Choose a password. It must have at least 12 characters, and it must not be your email address or a password from a list of leaked passwords.
-
Set up a second factor. The portal asks every administrator for one. Scan the QR code with an authenticator app, such as Google Authenticator, Microsoft Authenticator or 1Password, and type the 6-digit code that the app shows. You can use a passkey instead.
-
Save the ten recovery codes that the portal shows, in your password manager. Each code works once, if you ever lose your authenticator app. The portal shows them only now.
You are now signed in to the web portal. See Sign in and set up your account for more about passwords, second factors and recovery codes.
Step 1.7 - Create the Root CA and an Authority¶
In the web portal:
-
In the sidebar, choose Authority Manager. Under Root CAs, on the ECDSA root CA card, choose Create ECDSA root CA, and confirm.
You create the root CA only once. It signs the intermediate CA of every authority that you add later.
The card now shows the root CA's SHA-256 fingerprint. Copy it with the button next to it. You need it in step 2.2.
-
Choose Add authority, and fill in:
- Name:
My CA. The Authority ID becomesmy-ca. - Select authority type: Certificate Authority.
- Issue SSH certificates (SSH CA): tick it. This creates the authority's SSH CA.
- Allow one-time tokens and SSO login: leave it ticked. It is ticked by default.
Leave the other options as they are. You can change them later on the authority's page.
- Name:
-
Choose Add authority.
The SSH CA is now ready. For all the options of an authority, see Certificate authorities.
Get a Server Certificate¶
To get a server certificate from the CA, we need to use the BastionXP client utility: bxp-cli
Step 2.1 - Download BastionXP client¶
Follow the instructions here to download and install BastionXP Client bxp-cli in your machine.
Step 2.2 - Establish Trust with the Certificate Manager¶
Before you can get SSH certificates from the CA, the bxp-cli client must trust the BastionXP certificate authority. bxp-cli trust sets this up.
bxp-cli trust needs two values:
- the authority's ID,
my-ca; - the root CA's SHA-256 fingerprint, which you copied in step 1.7, from the root CA's card in Authority Manager.
Now make the client trust the CA:
$ bxp-cli trust --ca-url https://localhost --authority my-ca \
--fingerprint DE:E7:E7:C2:E2:64:AA:80:2A:5B:27:CA:A9:B0:F4:8D:60:2B:06:70:B8:CA:67:38:43:A1:52:B8:75:EC:8A:AC
Trusted: https://localhost
Authority: my-ca
Root: BastionXP Root CA
SHA-256: dee7e7c2e264aa802a5b27caa9b0f48d602b0670b8ca673843a152b875ec8aac
Saved in: /home/bob/.bxp-cli
The bxp-cli commands use this from now on.
bxp-cli trust fetches the root CA's certificate from the server. It accepts the certificate only if its fingerprint matches the one you gave.
Then it saves two files in the .bxp-cli folder in your home directory. tls_root_ca.crt is the root certificate. config.json holds the server's address and the authority's ID.
bxp-cli trust makes only bxp-cli trust the CA. If you also want other programs on this machine to trust it, add the root CA's certificate to the system trust store. On Debian and Ubuntu, run:
sudo cp ~/.bxp-cli/tls_root_ca.crt /usr/local/share/ca-certificates/bastionxp-ca.crt
sudo update-ca-certificates
After this, programs on this machine trust every TLS certificate that the BastionXP CA issues. For other operating systems, see Trust the CA.
Step 2.3 - Get the Host Certificate¶
To get a host certificate, you need a one-time token. Create it in the web portal:
- Open Authority Manager, and then the authority
my-ca. - Under One-time tokens, choose Create token, and select the purpose
HOST-CERTIFICATE.
The token is valid for 10 minutes.
Now get a signed SSH host certificate for localhost from the SSH CA:
$ bxp-cli ssh --token [HOST-CERTIFICATE token] --principal localhost
Certificate: /home/bob/.bxp-cli/ssh_host-cert.pub
Private key: /home/bob/.bxp-cli/ssh_host
Principals: localhost
Valid until: 2027-02-17 14:37 UTC
User CA key: /home/bob/.bxp-cli/ssh_user_ca.pub
This command did not give --key, so bxp-cli ssh created a new RSA host key. bxp-cli saved three files in /home/bob/.bxp-cli: the SSH host key, its certificate and the SSH user CA's public key:
Tip
You can also certify the host's existing SSH key, instead of a new one. Give the key with --key:
This writes the certificate to /etc/ssh/ssh_host_rsa_key-cert.pub. See SSH certificates.
Get a Client Certificate¶
Step 3.1 - Get the Client Certificate¶
You also use bxp-cli to get an SSH user certificate. First, create a token in the web portal, as in step 2.3, but with the purpose USER-CERTIFICATE. Then run:
$ bxp-cli ssh --token [USER-CERTIFICATE token]
Certificate: /home/bob/.bxp-cli/ssh_user-cert.pub
Private key: /home/bob/.bxp-cli/ssh_user
Principals: [email protected]
Valid until: 2026-11-19 22:37 UTC
Host CA key: /home/bob/.bxp-cli/ssh_host_ca-cert.pub
You'll find the SSH user key, its certificate and the SSH host CA's certificate in /home/bob/.bxp-cli:
Tip
You can also certify your existing key, instead of a new one. Give the key with --key:
This writes the certificate to ~/.ssh/id_rsa-cert.pub. ssh finds it there by itself. Note that the CA signs only RSA keys.
View the Issued Certificates:¶
We'll use the OpenSSH ssh-keygen tool to view and verify the SSH certificates generated.
SSH Root CA Certificate:¶
$ ssh-keygen -L -f /var/lib/bastionxp/ssh_host_ca-cert.pub
ssh_host_ca-cert.pub:
Type: [email protected] host certificate
Public key: RSA-CERT SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ
Signing CA: RSA SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ (using rsa-sha2-512)
Key ID: "localhost-19a72e58-db9a-4c94-a149-0ee743bbd9b3"
Serial: 0
Valid: from 2023-09-16T09:52:35 to 2123-08-23T09:52:35
Principals:
localhost
localhost
127.0.0.1
::1
Critical Options: (none)
Extensions: (none)
SSH Server Certificate:¶
$ ssh-keygen -L -f ~/.bxp-cli/ssh_host-cert.pub
ssh_host-cert.pub:
Type: [email protected] host certificate
Public key: RSA-CERT SHA256:i/JrxYvBvczFKNiaFYWWrSdPDLmGkz5xCzPvsuvc55U
Signing CA: RSA SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ (using rsa-sha2-512)
Key ID: "localhost-0f7795ee-c1fa-478e-af40-c2655ae71660"
Serial: 0
Valid: from 2023-09-16T09:56:40 to 2025-09-05T09:56:40
Principals:
localhost
Critical Options: (none)
Extensions: (none)
localhost in this case. This certificate cannot be used by any other host. If you provide, host1.example.com as the host name during certificate signing request, the SSH CA will issue a certificate with principals set to [host1.example.com].
BastionXP enforces identify based infrastructure access.
SSH User Certificate:¶
$ ssh-keygen -L -f ~/.bxp-cli/ssh_user-cert.pub
ssh_user-cert.pub:
Type: [email protected] user certificate
Public key: RSA-CERT SHA256:20vuGqOc8nFrdy4a8p/Rt2ui3H7g+XT/+wsxKed+Qhs
Signing CA: RSA SHA256:ydywz2m+Lc7iL3SpreSPAsr7/bfk77MZO6jeiGjsZ64 (using rsa-sha2-512)
Key ID: "[email protected]"
Serial: 0
Valid: from 2023-09-16T10:00:09 to 2023-09-16T18:00:09
Principals:
[email protected]
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc
[email protected]. Only user bob can use the above certificate to login via SSH into a host.
Also, the SSH user certificates are valid only for a short-period - 8 hours by default. Short-lived SSH user certificates provide fine-grained control over how long a user can have access to a previleged resource. It also avoids the SSH key sprawl problem.
Test using the SSH Certificates:¶
In the sections below, we'll use the SSH certificates generated above to configure an OpenSSH server to trust and permit logins using SSH user certificates issued by the SSH User Root CA.
SSH Server Configuration:¶
You can find the SSH host key, its certificate and the SSH user CA's public key in the following location: /home/bob/.bxp-cli
Copy these files to the /etc/ssh folder:
Configure the SSHd server to start using the SSH host certificate generated. Edit the /etc/ssh/sshd_config file as a sudo user and update the following configuration settings.
$ sudo nano /etc/ssh/sshd_config
...
HostKey /etc/ssh/ssh_host
HostCertificate /etc/ssh/ssh_host-cert.pub
TrustedUserCAKeys /etc/ssh/ssh_user_ca.pub
...
Finally, restart the SSHd service to make the configuration changes take effect. Verify if the SSHd is online, after the restart.
SSH Client Configuration¶
Edit the SSH client's known_hosts file and add the Host CA's SSH certificate as the certificate authority for the host, using the @cert-authority directive. This config will ensure that the SSH client will accept any SSH host certificate signed by the SSH host CA. It will not display any Trust On First Use (TOFU) message when the SSH client connects to the host. Add the contents of the ssh_host_ca-cert.pub file to the known_hosts file as shown below.
Note
Your known_hosts file may already have old entries for this host. Remove them with ssh-keygen -R localhost. Otherwise, ssh may warn that the host key changed.
Step 3.4 - SSH Login¶
An SSH user certificate lets you log in only with the login names in its principals. The certificate above has one principal, [email protected].
To log in as bob, the certificate must include the principal bob:
- In the web portal, give the user a role whose logins include
bob. - Run
bxp-cli sshagain. The new certificate's principals now includebob.
Now SSH login to the host VM using the OpenSSH client as shown below
bxp-cli does not open SSH connections itself. You use ssh to log in. ssh finds the certificate ~/.bxp-cli/ssh_user-cert.pub by itself, because it is next to the key.
If the SSH host server name is host1.example.com and the user bob has the permission to login to the server, you can ssh into the server as follows using the SSH user certificate:
ssh -i ~/.bxp-cli/ssh_user [email protected]
Congratulations! You have successfully set up a private SSH CA. You also generated host and user certificates, used them to setup and login to a OpenSSH server using OpenSSH client.
Next Steps:¶
- Configure the BastionXP SSH CA to issue SSH certificates after a successful OIDC SSO Login using OIDC SSO providers such as Microsoft Azure 365, Google G-Suite, Okta, or Keycloak.
Questions
If you have any questions or suggestions, please email us at: support@bastionxp.com