SSH encrypts a remote shell or file copy. Keys replace repeated passwords: a private key stays on your machine; the server stores the public half. This lesson covers key generation, `authorized_keys`, agents, and pitfalls like forwarding.
Widgets: comparison table contrasts password vs key auth for ops concerns. Graph shows where trust is stored (client private key vs server authorized_keys). Code explorer walks through keygen → install → permissions → agent. Tabbed code covers multi-host config and host-key trust.
| Password | SSH key pair | |
|---|---|---|
| Brute force / spraying | Vulnerable to guessing and reuse across sites | Ed25519/RSA key space; combine with PasswordAuthentication no on servers |
| Automation / CI | Tempts embedding secrets; MFA breaks non-interactive flows | CI uses deploy keys or short-lived certs; Ansible uses ssh-agent or sshpass (avoid) |
| Rotation / revocation | Change password everywhere it was reused | Rotate key pair: add new pubkey, verify login, remove old line from authorized_keys |
| Audit | Hard to prove which human used shared account | Per-key comments in authorized_keys; per-host keys in config |
Graph: center is sshd. Your private key never leaves the laptop—it only signs a challenge. The server only ever saw the public line copied into authorized_keys. Compromise of the server does not leak your private key file back from disk (unless you forward the agent unwisely).
ssh-keygen -t ed25519 -C "you@example.com"
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519
Host prod
HostName 10.0.1.50
User deploy
IdentityFile ~/.ssh/prod_ed25519
ServerAliveInterval 60