ssh, updated

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.

TypeRecommended sizeUse when
ed25519fixed 256-bitdefault choice — fast, small, PQ-adjacent
ecdsaP-256legacy clients that lack Ed25519
rsa4096-bitFIPS 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

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

  1. Generate a new key pair.
  2. Deploy the new public key (via authorized_keys or a new CA-signed cert).
  3. Confirm the new key works before removing the old one.
  4. Remove the old public key from authorized_keys or revoke the old cert via RevokedKeys in sshd_config.

Automate this. If key rotation requires a ticket, it happens too rarely.

§ home
~/knubertus/home/
1,1 Top