Use this when protecting private keys for TLS, SSH and signing.
Private Keys
Private keys used for TLS, SSH and signing are secrets of the highest value. Store them encrypted with restrictive permissions, ideally in an HSM, TPM or vault, and rotate them on exposure.
1. Private keys (TLS, SSH, signing) must be protected.
2. File permission 600, encrypted at rest.
3. HSM/KMS for high value.
4. Rotate and revoke if exposed.
5. Inventory.
key → protected storage → use
Context & applicabilityCommon mistakes · platform/version boundaries
- Exportable private keys in Windows stores for keys that should never leave the server.
- Keys in container images.
- No inventory of where each key is used.
- Backups of HSM keys missing, so HSM failure loses keys.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Encrypted at rest with tight permissions.
- HSM or TPM for high value keys.
- Revoke and replace on exposure.
find / -name '*.pem' -o -name '*.key' 2>/dev/null | xargs ls -l— key file permissions- HSM/KMS usage — non-exportable keys
gitleaks detect— keys in repos
ReferenceWhy it matters1 section · depth on demand
Protecting private keys
- Generate where used; prefer non-exportable storage (HSM, TPM, cloud KMS, YubiKey).
- File permissions
600; passphrase-protected if on disk. - Separate keys per purpose (TLS, signing, SSH) and per system.
- Short-lived certificates (ACME, SSH certificates) reduce the impact of a stolen key.
- Revoke and replace immediately on exposure.
ReferenceImportant terms & boundaries2 sections · depth on demand
Storage options
| Option | Protection |
|---|---|
File with chmod 600 | Basic, readable by root |
| Encrypted with passphrase | Protects at rest |
| OS key store (Windows CNG, macOS Keychain) | Non-exportable keys possible |
| TPM / Secure Enclave | Bound to the device |
| HSM / cloud KMS | Never leaves the device; usage audited |
| Hardware token (YubiKey) | Personal SSH/PGP keys |
In depth
Private keys are the secret half of asymmetric key pairs used for TLS servers, SSH, code signing, document signing and certificate authorities. Anyone with the private key can impersonate its owner, so key protection is fundamental to PKI.
| Key | Protection |
|---|---|
| CA keys | HSM, offline root CA |
| Code signing keys | HSM or cloud KMS; signing service, never on developer laptops |
| TLS server keys | File permissions (0600), per-server keys, automated renewal |
| SSH user keys | Passphrase or hardware key (FIDO2), agent forwarding avoided |
If a private key is exposed, revoke the associated certificate, replace the key (not just the certificate) and investigate where the key was used.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Secrets Management → Private Keys. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html · confidence 94%