Skip to content

Lesson 2 of 14 · 18m

SSH as the Control Plane

~/.ssh/config, ed25519 keys, ProxyJump instead of agent forwarding, and -L tunnels that make open ports unnecessary.

SSH on a self-hosted box is not a login method — it's the transport for almost everything you do. rsync moves files over it, git push deploys over it, -L tunnels reach databases over it, ssh -J chains hosts over it. Operators who treat it as "the way I get a shell" end up opening ports that a tunnel would have made unnecessary.

~/.ssh/config is the real control plane

Host tower
    HostName 203.0.113.10
    User deploy
    IdentityFile ~/.ssh/id_ed25519_tower
    IdentitiesOnly yes

Now ssh tower does everything. IdentitiesOnly yes matters more than it looks: without it, ssh offers every key in your agent in sequence, and a server with MaxAuthTries 6 can lock you out with the right key sitting fourth in line.

Key types, briefly: ssh-keygen -t ed25519 is the default you want — short keys, fast signatures, no NIST curves. RSA 4096 survives for ancient peers; note that OpenSSH 8.8 (2021) disabled the ssh-rsa SHA-1 signature scheme by default, and a client that needs -o PubkeyAcceptedAlgorithms=+ssh-rsa to log in is a client telling you to retire that box. Hardware tokens get ed25519-sk, which requires a FIDO2 touch — stolen key file, still useless.

ForwardAgent is the trap, ProxyJump is the tool

ssh -A (or ForwardAgent yes) exports your agent socket to the remote as /tmp/ssh-XXXX/agent.PID. Your private key never leaves your laptop — but while you're connected, root on that remote host can point SSH_AUTH_SOCK at your socket and authenticate as you, to anywhere your key is trusted. On a box you fully control and nobody else roots, it's convenient. Everywhere else it's an exported signing oracle.

The correct primitive is ProxyJump: ssh -J bastion internal chains the TCP connection through the bastion while your client authenticates to the target directly — the bastion sees an encrypted stream it cannot impersonate. In config: ProxyJump bastion.

Tunnels replace open ports

ssh -L 5433:127.0.0.1:5432 deploy@tower

While that session lives, localhost:5433 on your laptop is the server's 127.0.0.1:5432 — encrypted, authenticated, and gone when you disconnect. Postgres, Redis, a one-off admin UI, a metrics endpoint: reach all of them this way and none of them ever need a published port or a firewall exception. -R does the inverse (expose your laptop's port to the remote), -D 1080 makes a SOCKS proxy out of the whole connection for browser debugging.

Two files worth not confusing: authorized_keys is who may log in; known_hosts is which servers you trust. That first-connection fingerprint prompt is trust-on-first-use — StrictHostKeyChecking accept-new takes the convenience without taking the silence when a key changes. When you rebuild a box, ssh-keygen -R tower clears the stale entry; a changed host key is the MITM alarm working as designed, not an annoyance to reflexively bypass.

Key material quality is not theoretical: in 2008 Debian shipped an OpenSSL RNG seeded by process ID (CVE-2008-0166), which made every key generated on those systems predictable; Debian carried an ssh-vulnkey blacklist for years afterward. mosh earns a mention for flaky links — UDP, local echo, survives roaming between Wi-Fi and LTE — and when a connection misbehaves, ssh -vvv narrates exactly which key was offered and which config line was read; it answers "why didn't it work" faster than guessing.

Field notes

  • MaxAuthTries 3, LoginGraceTime 20s, and AllowUsers deploy in sshd_config shrink the window further; sshd -T dumps the effective config when includes get creative.
  • ssh -o Foo=bar overrides anything in config for one shot — use it instead of editing the file for experiments.
  • scp is deprecated-ish in upstream OpenSSH; reach for rsync or sftp and be happier.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.