Pcornel
Linux · Certificates & TLS

Private Keys

Cheat sheet · https://pcornel.dk/topic.php?topic=2868

Back to the Topic

Answer

A private key is the secret half of a key pair used by a TLS service or SSH; whoever has it can impersonate the service.

Remember

Permissions 600 (or 640 with a service group), owned by root or the service. Do not email or commit keys. Check the key matches the certificate by comparing public keys. Prefer EC (P-256) or RSA ≥ 2048.

First checks

  • openssl x509 -in <cert> -noout -subject -issuer -dates -ext subjectAltName — certificate details
  • openssl s_client -connect <host>:443 -servername <name> </dev/null — live chain and verification
  • openssl verify -CAfile <ca> -untrusted <chain> <cert> — chain validation
  • trust list | head / ls /etc/ssl/certs — system trust store

Commands

openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out server.key
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out server.key
openssl genpkey -algorithm ED25519 -out signing.key

Verify in this order

key generated → stored with strict permissions → paired with its certificate → used by the service

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2868

Confirmation

Confirm action

Continue?