Implement SSH Certificate Authority on Linux Servers

Why use an SSH certificate authority on Linux servers

For Linux system administrators and security engineers, an SSH certificate authority provides centralized authentication and short lived credentials, making access scalable and auditable. Using an SSH certificate authority on Linux reduces key sprawl, eases revocation, and integrates with automation pipelines, which matters in dynamic infrastructure.

This guide shows practical steps to deploy an OpenSSH CA, sign host and user certificates, configure servers to trust the CA, automate issuance and rotation, and troubleshoot real world problems. Examples assume common Linux distributions running OpenSSH.

Benefits of CA based SSH key management

Replacing individual public keys with signed certificates gives you central control, simpler onboarding, and time limited access. Certificates carry metadata such as principals and expiration, so you can grant scoped access without distributing private keys.

Operational benefits include reduced operator friction and improved security hygiene. Auditing and revocation get simpler because you can revoke a CA issued credential, or rotate the CA, rather than track down every copied public key.

Prerequisites and security considerations

Before you start, ensure OpenSSH server and client packages are up to date, preferably OpenSSH 7.9 or later for feature parity. You need a hardened host to hold the CA private key, ideally an air gapped or bastion instance with strict access controls and automated backups.

See also  Tune ext4 and XFS on Linux for Database Performance

Consider hardware security modules or dedicated key management services for high assurance. Plan your certificate lifetimes conservatively, for example hours for user sessions, days for hosts, and document emergency rotation and revocation procedures.

Generate and secure the OpenSSH CA key

Create a dedicated keypair for signing certificates on the CA host. Use strong key types, and protect the private key with file permissions and optional passphrase. Example command to create a signing key is:

ssh-keygen -t ed25519 -f /etc/ssh/ca_user_key -C "ssh ca key"

After generation, lock the private key down, for example with owner root only permissions, and store a copy in an encrypted backup. Limit interactive access to the CA host, and log all signing operations to support audits.

Configure Linux SSH servers to trust the CA

Distribute the CA public key to all target Linux SSH servers and reference it in the server configuration. For user certs add the CA public key in the SSH authorized keys trust file, for example in sshd_config use the TrustedUserCAKeys directive. Example lines to add are:

SSH certificate authority on Linux
  • Place the CA public key on the server, for example in /etc/ssh/ca_user_key.pub
  • Edit /etc/ssh/sshd_config to include TrustedUserCAKeys /etc/ssh/ca_user_key.pub, then restart sshd

For host certificates, add the CA public key to the server’s known hosts trust by configuring the HostbasedAcceptedKeyTypes or by verifying host certificates on clients with the CA public key. Test configuration changes in a staging pool before rolling to production.

Issue and sign host and user certificates

Signing a user public key creates a certificate that clients present when connecting. Use the CA private key and specify principals and expiry. Example user signing:

See also  Optimize PostgreSQL on Linux for High Concurrency Workloads

ssh-keygen -s /etc/ssh/ca_user_key -I alice -n alice -V +1h alice.pub

  • -I sets a certificate identity, -n sets valid principals, -V sets validity window
  • Host certificates use -h to mark a signing operation for host keys

After issuing certificates, distribute certificate files alongside private keys on client systems or provision them through an automated agent. Always verify certificates by attempting an SSH connection to a test server that trusts the CA.

Automate issuance and rotation with scripts and Ansible

Automation reduces human error. For ephemeral user certificates, build a signing API or lightweight agent on the CA host, protected by an authentication layer, to sign keys on demand. Generate certificates with a short TTL and return them to the requesting client over an encrypted channel.

Use configuration management tools such as Ansible to push CA public keys and rotate server config. A basic Ansible task sequence includes copying the CA public key, updating sshd_config, and restarting sshd in a controlled rollout. Track certificate lifetimes and schedule automatic renewals.

Revocation and rotation procedures

OpenSSH does not use a traditional certificate revocation list for user certificates, so design multiple controls. Short lived certificates reduce revocation needs. For hosts, maintain a revocation file and configure sshd to consult it if your OpenSSH build supports it. Plan CA key rotation in stages to avoid outages, by deploying the new CA public key in trust stores before switching signing to the new key.

Document emergency steps for immediate credential disabling, such as disabling the CA signing service, removing CA keys from servers, and updating firewall or PAM controls. Test the rotation playbook periodically in a staging environment.

See also  Linux kpatch Live Kernel Patching: Deploy and Automate

Troubleshooting common CA problems

Authentication failures are often caused by mismatched principals, expired certificates, or misconfigured TrustedUserCAKeys paths. Check sshd logs on servers, and use verbose client output with ssh -vvv to see certificate negotiation details and errors.

If certificates are rejected for bad principals, ensure the certificate contains the expected username in the principals list. For host verification problems, confirm the client trusts the host CA public key and that host certificates are signed with the host CA, not the user CA.

Conclusion and FAQs

Implementing an SSH certificate authority on Linux transforms SSH access from a static key management problem into a centralized, auditable workflow. By generating a dedicated CA keypair, distributing CA public keys to servers, and signing host and user keys with appropriate lifetimes, teams can scale SSH access while reducing exposure from long lived keys. Automation is a force multiplier, so integrate a signing service with authentication, or use configuration management to consistently apply trust across servers. In production, enforce least privilege by assigning narrow principals, use short certificate windows for interactive sessions, and embed rotation and emergency revocation steps into runbooks.

Q: How long should user certificates last? A: Prefer short lived certificates, for example one hour to eight hours depending on your workflow, to limit risk from compromised clients. Q: Can I use the same CA for hosts and users? A: You can, but separating host and user CAs improves compartmentalization and reduces blast radius if a CA private key is compromised.

Q: How do I revoke a certificate quickly? A: With short lived certificates revocation is often handled by waiting for expiry. For urgent cases, remove the CA public key from server trust or block the signed private key at network or IAM layers. Q: Is HSM recommended for the CA key? A: Yes, using an HSM or cloud KMS increases key security and reduces the likelihood of private key exfiltration, especially for production scale environments.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top