Join our Newsletter — 33% off our NHI Course
Home› Guides› SSH Key and SSH Certificate Management Guide
Guide Non-Human Identity (NHI)

SSH Key and SSH Certificate Management Guide

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 24 October 2026 17 min read
On this page

SSH keys are among the oldest and least governed non-human credentials in most organisations. They grant shell access to servers, network devices, Git repositories and cloud instances, often with root-level privileges. A plain public key in an authorized_keys file has no expiry unless someone adds one, is rarely tied to an owner, and survives the departure of the person or system that created it. NIST IR 7966 notes that some large enterprises have hundreds of thousands or even millions of SSH user keys for automated access, often providing many more entry points onto servers than interactive user accounts do. This guide is for infrastructure, identity and security teams, and covers discovery, certificates, brokered access, automation and AI agent keys, hardening, detection and a phased roadmap.

Key takeaways

  • Every authorised key is an access grant. Each authorized_keys line lets a private key holder into an account, so treat it like one: approved, owned, reviewed and removed.
  • Discover before you change anything. Inventory SSH servers, authorised keys, identity keys and the trust relationships between them; NIST IR 7966 calls a full inventory of private keys infeasible, so the authorised key side is the anchor.
  • Short-lived certificates remove most sprawl. Servers trust a CA instead of individual keys, but OpenSSH certificates are valid forever by default, so set lifetimes deliberately and protect the CA key.
  • Broker privileged SSH. Route administrative access through a bastion or PAM gateway with strong authentication and session recording, and lock authorised keys so users cannot add their own backdoors.
  • Automation and AI agent keys are NHIs. Give each its own restricted key or certificate, with an owner, a forced command, a source restriction and a rotation date, and never hand an agent a person's keys.

How SSH authentication works

SSH makes two trust decisions. The client authenticates the server with a host key, which stops a man-in-the-middle posing as the server; the server then authenticates the user or process, usually with a password, Kerberos or a public key. NIST IR 7966 recommends public key authentication for automated access because it supports command and source restrictions, and it notes that public key trust is explicit: who can reach an account can be read from the destination host, provided authorised keys are controlled.

MechanismWhat the server or client trustsWhere trust is storedExpiry
User keyA specific public key for a specific accountauthorized_keys (by default .ssh/authorized_keys and .ssh/authorized_keys2)None unless the expiry-time= option is set
Host keyA specific public key for a specific serverknown_hosts on each clientNone; replaced only by rotation
User certificateAny key signed by a trusted user CA for listed principalsTrustedUserCAKeys on the serverThe validity interval set at signing
Host certificateAny host key signed by a trusted host CA@cert-authority line in known_hostsThe validity interval set at signing
FIDO-backed keyA key whose private part cannot leave the authenticatorauthorized_keys or a certificateAs for user keys; needs the device present
  • Identity keys: the private key the client holds. IR 7966 says identity keys for interactive users should be protected by a passphrase, but notes that keys for automated access are usually unencrypted files, so file location and permissions are the real control. The ssh-keygen manual adds that host keys must have an empty passphrase.
  • Agent forwarding: lets a remote host use your local agent for onward connections. The ssh_config manual warns that users able to bypass file permissions on the remote host can use the forwarded agent to authenticate with your identities, even though they cannot extract the key.
  • Key types: current ssh-keygen generates Ed25519 by default and supports FIDO-backed ed25519-sk and ecdsa-sk keys. OpenSSH 10.0 (April 2025) removed DSA support entirely.

The risks

NIST IR 7966 groups SSH vulnerabilities into seven categories, most of them governance failures rather than cryptographic weaknesses.

  • Key sprawl and unknown trust: keys copied to many servers and never removed. IR 7966 says many organisations do not know how many keys grant access or who holds copies.
  • Stolen, leaked and unterminated keys: copies taken from hosts, backups, laptops or repositories, or left behind by leavers and retired automation. MITRE ATT&CK technique T1552.004 describes attackers searching ~/.ssh for private keys and brute-forcing passphrases offline. See the Leaked Credential Response Playbook.
  • Backdoor keys: IR 7966 explains that adding one line to an authorized_keys file creates access that bypasses a privileged access management system, and that such keys can stay unnoticed for years.
  • Pivoting: malware or an intruder uses keys found on one host to reach the next. IR 7966 warns that in dense estates an attack may spread to most servers after the first few.
  • Over-privileged, shared and unintended use: keys authorised for root or able to run any command, one key shared by a team, or a file transfer key used to tunnel traffic past network controls.
  • Host key exposure: a leaked host private key lets an attacker in the traffic path impersonate the server. The GitHub RSA SSH Host Key Exposure 2023 forced a global rotation and known_hosts updates for every client using the RSA key.
  • Vulnerable implementation: SSH itself can be targeted. The XZ Utils Backdoor 2024 (CVE-2024-3094) could interfere with sshd authentication on some Linux builds before it was caught.

Discovery and clean-up

IR 7966 recommends an inventory and remediation project, and calls manual discovery across an enterprise "practically impossible", so automate it. Back up SSH configurations before each change.

  1. Find SSH servers with existing vulnerability scanning, including network devices.
  2. Collect authorised keys from every account, including non-standard paths set by AuthorizedKeysFile and keys served by AuthorizedKeysCommand. Record the account, host, key fingerprint and options such as from= and command=.
  3. Find identity keys on servers, laptops, CI systems, images and repositories, and match them to authorised keys. Flag orphan authorised keys with no known identity key: IR 7966 treats them as possible backdoors.
  4. Map trust relationships and flag those that cross environments (development to production), cross authorisation boundaries, reach root, or allow both incoming and outgoing key trust on one account.
  5. Assign owners using a configuration database where possible. See the NHI Ownership Guide and the Service Account Inventory Template.
  6. Lock down keys by moving authorised keys to root-owned locations that ordinary users cannot write, and point AuthorizedKeysFile there.
  7. Monitor usage, then remove. IR 7966 suggests usually six to twelve months of log monitoring, including disaster recovery tests, before removing unused keys that nobody approves keeping.
  8. Rotate what remains and replace keys that fail algorithm and length policy. External keys used with partners need coordinated, manual rotation.

Moving to SSH certificates

An OpenSSH certificate is a public key plus an identity, principals, options and a validity interval, signed by a CA key. Servers and clients then trust the CA rather than many individual keys. The ssh-keygen manual describes this as a different and much simpler format than the X.509 certificates used for TLS.

PropertyPlain authorised keysSSH certificates
Trust configurationOne line per key per account per hostOne CA key per server (TrustedUserCAKeys)
Who may log in as whatImplied by which file holds the keyPrincipals in the certificate, optionally checked against AuthorizedPrincipalsFile
LifetimeIndefinite by defaultSet by -V at signing; indefinite if omitted
RevocationRemove the line from every hostExpiry, or a Key Revocation List via RevokedKeys
Audit trailKey fingerprintKey identifier (-I) logged by the server
Main riskSprawl and orphaned keysCompromise or misuse of the CA key
  • Issue certificates after SSO and MFA with lifetimes measured in hours for people, and put the allowed principals in the certificate. The sshd_config manual says certificates without principals are not accepted through TrustedUserCAKeys.
  • Always set a validity interval. The ssh-keygen manual states that by default certificates are valid from the Unix epoch to the distant future, which recreates the long-lived key problem.
  • Use host certificates (HostCertificate on the server, @cert-authority in known_hosts) so clients can verify hosts without trust-on-first-use prompts.
  • Protect the CA signing key. ssh-keygen can sign with a CA key held in a PKCS#11 token or an agent. See the Cryptographic Key Management Guide.
  • Plan revocation. Publish a KRL with RevokedKeys, replace it atomically, and remember that the manual says an unreadable revocation file blocks public key authentication for all users.
  • Keep an issuance record. IR 7966 (2015) cautioned that a host trusting a CA cannot show who may access it by inspecting the host alone, so log every certificate issued and its principals.

Short-lived certificates are a form of just-in-time access. See the JIT Access Guide and the Machine Identity, PKI and Certificate Lifecycle Guide.

Brokered and privileged SSH

A broker gives users access to production without holding production keys, and closes the backdoor route IR 7966 describes if authorised keys are locked and monitored. IR 7966 also recommends reviewing key-based trust inside existing privileged access reviews.

  • Route administrative SSH through a bastion or PAM gateway that authenticates the person with MFA and issues a short-lived certificate or injects a vaulted credential. See the Privileged Access Management Guide.
  • Record privileged sessions and keep the key identifier or certificate ID with each recording. See the Privileged Session Management Guide.
  • Use jump hosts, not agent forwarding. ProxyJump connects to the target through the jump host without exposing your agent there. Client ForwardAgent is off by default, while the server's AllowAgentForwarding defaults to yes.
  • Consider removing inbound SSH where a cloud provider's session service authenticates with cloud identity and logs sessions centrally.

SSH keys for automation and NHIs

Automated access is where most keys live. IR 7966 recommends that requests for automated access name the allowed command, source hosts, business process and owner, and that automation keys carry command and source restrictions unless specially approved.

authorized_keys optionWhat it does (per the sshd manual)Use for
restrictDisables port, agent and X11 forwarding, PTY allocation and ~/.ssh/rc, including future restrictionsEvery automation key, then re-enable only what is needed
command="..."Runs a fixed command whenever the key is used, ignoring the client's commandBackups, file transfer and single-purpose jobs
from="..."Requires the client's name or address to match a pattern list, including CIDRLimiting a stolen key to known source hosts
expiry-time="..."Rejects the key after a set dateTemporary and contractor access
cert-authority with principals="..."Trusts a CA for this account, only for listed principalsMoving one account to certificates
  • One key per automation, never shared. Duplicated identity keys break accountability and are listed by IR 7966 for remediation; OWASP lists NHI reuse as NHI9:2025.
  • Prefer short-lived certificates issued to a workload identity. See the Workload Identity Federation Guide.
  • Scope Git access. For CI, prefer the platform's short-lived OIDC-based credentials and deploy keys limited to one repository. See the CI/CD Pipeline Identity Security Guide.
  • Rotate on reassignment. IR 7966 says automation keys should be changed when an administrator who managed them is reassigned or leaves. See the Service Account Security Guide and the Secrets Management Guide.

AI agents and SSH

Agents that run shell commands can read the same home directories where SSH keys sit. MITRE ATT&CK records that in its "AI-Assisted Breach of Mexico's Government Infrastructure" campaign (C0064) the adversary tasked Claude Code to harvest credentials and SSH keys, and to establish persistence by injecting an SSH key into /root/.ssh/authorized_keys through a crontab script. Keep agents away from a person's ~/.ssh and agent socket, issue them their own short-lived, principal-scoped certificates, and alert on any authorised key change made from an agent's session. See the AI Coding Agents Security Guide.

Hardening basics

IR 7966 lists the policy areas: enable SSH only where needed, keep it current, disable unapproved authentication methods, limit SSH-accessible accounts including root, disable forwarding and use approved algorithms. Defaults below are from the current OpenSSH manuals.

SettingOpenSSH defaultRecommended position
PasswordAuthenticationyesno, once keys or certificates are in place
PermitRootLoginprohibit-passwordno; use named accounts with logged sudo, or forced-commands-only for a reviewed exception
AuthorizedKeysFile.ssh/authorized_keys .ssh/authorized_keys2A root-owned path per user, or none when using certificates only
TrustedUserCAKeys / RevokedKeysNo CA or revocation list unless configuredSet to your user CA and a current KRL
AllowAgentForwarding, AllowTcpForwardingyesno, except on approved jump hosts; the manual notes this only helps if users are also denied shell access
LogLevelINFOAt least INFO and centrally collected; avoid DEBUG, which the manual says violates user privacy
  • Retire weak keys. DSA is gone from OpenSSH 10.0; replace short RSA keys with Ed25519, and use FIDO-backed keys for administrators. See the Hardware Security Keys Guide.
  • Patch quickly. In its 10.6 release notes (October 2026) OpenSSH said many security reports now come from AI-assisted research and that it will release more often. See the Linux Server Hardening Guide.
  • Track key exchange. OpenSSH 10.0 made hybrid post-quantum mlkem768x25519-sha256 the default. See the Post-Quantum Readiness Guide.

Detection and monitoring

IR 7966 recommends comparing every configured authorised key against an approval record, alerting on any key without one, and analysing logs for unused keys and connections from unapproved sources.

TechniqueWhat to watchSignal
T1098.004 SSH Authorized KeysChanges to authorized_keys on hosts, and key changes through cloud APIsNew key with no approval; write by an unexpected process; instance metadata key added
T1552.004 Private KeysReads of ~/.ssh and key files by unusual processesBulk access to key files; archiving or exfiltration after access
T1563.001 SSH HijackingAgent sockets and existing sessionsOne process using another user's agent socket; lateral SSH without a new authentication
Unapproved key useAuthentication logs with fingerprint or certificate key IDKnown key from a new source; dormant key suddenly used; root login

ATT&CK notes that attackers can add keys through cloud interfaces, such as Google Cloud's metadata commands or an Azure API request, so monitor control planes as well as hosts. It also records Salt Typhoon adding authorised keys under root or other users on compromised network devices, which are often outside host-based monitoring. See Salt Typhoon Telecom Intrusions 2025. See the Linux Detection and Response Guide.

Framework mapping

An NHI Mgmt Group alignment checked against the framework texts. IR 7966 maps to SP 800-53 Rev. 4 and CSF 1.0; the identifiers below use current versions.

Control areaNIST CSF 2.0NIST SP 800-53 Rev. 5ISO/IEC 27001:2022 Annex ACIS Controls v8.1OWASP NHI Top 10
Inventory of keys and trust relationshipsPR.AA-01, ID.AM-08CM-8, IA-5, AC-25.9, 5.165.1, 5.5NHI1
Approved provisioning and removalPR.AA-01, PR.AA-05AC-2, AC-2(3), IA-55.17, 5.185.3, 6.1, 6.2NHI1
Least privilege on key grantsPR.AA-05AC-6, AC-175.15, 8.25.4, 6.8NHI5, NHI8
Certificates and CA key protectionPR.AA-01, PR.AA-03IA-5(2), SC-128.5, 8.246.7NHI7
Private key protectionPR.DS-01IA-5(6), IA-5(7)5.173.11NHI2, NHI9
Brokered privileged and remote accessPR.AA-03, PR.AA-05AC-17, AC-17(4), MA-48.2, 8.56.4, 6.5NHI10
Logging and monitoringPR.PS-04, DE.CM-03, DE.CM-09AU-2, AU-6, AU-12, SI-48.15, 8.168.2, 8.5, 8.11n/a
Secure configuration and patchingPR.PS-01, PR.PS-02CM-6, CM-7, SI-28.8, 8.94.1, 7.1NHI4

Common failure patterns

  • Clean-up without lock-down. Keys are removed but users can still edit authorized_keys, so sprawl and backdoors return.
  • Certificates that never expire. A CA is deployed but signing scripts omit a validity interval, so certificates inherit the "forever" default.
  • A CA key on a file share. The signing key every server trusts is stored like an ordinary key.
  • Bastion with a side door. A PAM gateway records sessions, but direct key logins still work, which is exactly the bypass IR 7966 describes.
  • Removing keys too fast. Keys unused for a few weeks are deleted and a quarterly or disaster recovery job fails.
  • Host key rotation with no verification path. When a host key must change, as in the GitHub RSA SSH Host Key Exposure 2023, users who cannot check the new fingerprint may accept an impostor's key. UpdateHostKeys and host certificates ease planned rotation.
  • Automation keys with a shell. Backup or transfer keys without a forced command or source restriction give a thief full interactive access.

Metrics that show progress

MetricWhat it showsTarget direction
Authorised keys with a named owner and approvalGovernance coverageUp, towards 100%
Authorised keys unused in the observation windowStanding access nobody needsDown
Keys granting root or crossing environmentsHighest-impact trust relationshipsDown
Automation keys with command and source restrictionsBlast radius of a stolen keyUp
Interactive logins using short-lived certificatesProgress away from static keysUp
Hosts with authorised keys locked to root-owned pathsResistance to backdoor keysUp
Time to detect an unapproved authorised keyMonitoring effectivenessDown
Keys failing algorithm policy (DSA, short RSA)Cryptographic hygieneDown, towards zero

See the Identity Security Metrics Guide.

Implementation roadmap

PhaseFocusOutcomes
First 30 daysVisibility and quick winsSSH server list; authorised key collection on critical hosts; root login and password authentication disabled where safe; private key scanning of repositories and images
Days 31 to 90Ownership and lock-downTrust relationship map; owners assigned; environment-crossing and root keys reviewed; authorised keys moved to root-owned paths; fingerprint logging into the SIEM; alerting on unapproved keys
Days 91 to 180Certificates and brokeringUser CA with protected signing key; short-lived certificates for administrators via SSO and MFA; bastion or PAM gateway for production; host certificates; restrictions on all automation keys
After 180 daysRemove static keysUnused keys removed after the observation window; remaining keys rotated; automation on workload-issued certificates

For lifecycle processes that cover keys alongside other NHIs, see the NHI Lifecycle Management Guide.

Practitioner checklist

  • Inventory SSH servers, authorised keys and identity keys (including in code, images and backups), and map trust relationships.
  • Assign an owner and an approval record to every authorised key; remove orphan keys after review.
  • Move authorised keys to root-owned locations and monitor them against the approved baseline.
  • Observe key usage for six to twelve months, then remove unused keys and rotate the rest.
  • Disable password authentication and direct root login; retire DSA and short RSA keys.
  • Issue short-lived user certificates after SSO and MFA, always with a validity interval and principals.
  • Protect the CA signing key in hardware and publish a Key Revocation List.
  • Broker and record privileged SSH, and use ProxyJump instead of agent forwarding.
  • Apply restrict, command= and from= to every automation key; one key per automation.
  • Give AI agents their own scoped certificates and keep personal keys and agent sockets out of their reach.

Standards and references

Related NHI Mgmt Group resources: Privileged Access Management Guide · Machine Identity, PKI and Certificate Lifecycle Guide · Secrets Management Guide · NHI Lifecycle Management Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 24 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.