SSH Key Management — Quick Reference
A concise reference for generating, deploying, and rotating SSH keys across Linux infrastructure. Covers key types, authorized_keys hygiene, and certificate-based auth.
Key types
Use Ed25519 everywhere you control both ends of the connection. Fall back to ECDSA P-256 only when the remote sshd or client library does not support it. RSA is acceptable at 4096-bit; never use RSA-1024 or DSA.
| Type | Recommended size | Use when |
|---|---|---|
ed25519 | fixed 256-bit | default choice — fast, small, PQ-adjacent |
ecdsa | P-256 | legacy clients that lack Ed25519 |
rsa | 4096-bit | FIPS environments requiring RSA |
Generating a key pair
ssh-keygen -t ed25519 -C "user@host $(date +%Y-%m)" -f ~/.ssh/id_ed25519_ops
Always set a passphrase. Use ssh-agent to avoid retyping it every session:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_ops
Deploying to a remote host
ssh-copy-id -i ~/.ssh/id_ed25519_ops.pub user@target.host
Or manually — append the public key to ~/.ssh/authorized_keys on the remote:
cat ~/.ssh/id_ed25519_ops.pub | ssh user@target.host \
"mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
authorized_keys hygiene
Each line in authorized_keys supports options that tighten what a key is allowed to do:
restrict,command="/usr/local/bin/backup-only.sh" ssh-ed25519 AAAA... backup@ci-runner
from="10.42.0.0/16",no-agent-forwarding,no-X11-forwarding ssh-ed25519 AAAA... deploy@bastion
restrictdisables port forwarding, agent forwarding, PTY allocation, and X11 — use it as a baseline for service keys, then re-enable only what’s needed.from=restricts which source IPs may authenticate with this key. Combine with firewall rules; don’t rely on it alone.command=forces a specific command regardless of what the client requests.
Certificate-based authentication
For fleets larger than a handful of hosts, per-host authorized_keys files become unmanageable. Use an SSH CA instead:
# Create the CA key (done once, stored offline or in a vault)
ssh-keygen -t ed25519 -f /etc/ssh/ca/user_ca -C "secops-user-ca-2026"
# Sign a user's public key — valid for 8 hours, only for the ops role
ssh-keygen -s /etc/ssh/ca/user_ca \
-I "elena@ops-$(date +%Y%m%d)" \
-n ops \
-V +8h \
~/.ssh/id_ed25519_ops.pub
Add to every host’s sshd_config:
TrustedUserCAKeys /etc/ssh/ca/user_ca.pub
Users now authenticate with their signed certificate — no authorized_keys entries needed, and access expires automatically.
Key rotation
- Generate a new key pair.
- Deploy the new public key (via
authorized_keysor a new CA-signed cert). - Confirm the new key works before removing the old one.
- Remove the old public key from
authorized_keysor revoke the old cert viaRevokedKeysinsshd_config.
Automate this. If key rotation requires a ticket, it happens too rarely.