OGOPSEC Brand Mark
OGOPSECOBSIDIAN GOOSE

OGOPSEC // Dispatch

SSH Key Authentication: Set It Up, Lock It Down

By Jamie Folsom ·

SSH key authentication is the standard way to log into a Linux server without typing a password, and it is a genuine security upgrade rather than just a convenience. Instead of proving who you are with a secret that can be guessed or phished, you prove it with a cryptographic keypair: a public key the server trusts, and a private key that never leaves your control. This post covers how that exchange actually works, how to set it up without the common mistakes, and how to protect the private key everything hinges on.

How the key exchange works

You generate a pair of mathematically linked keys. The public key is safe to share and gets placed on the server. The private key stays on your machine. When you connect, the server uses your public key to issue a challenge that can only be answered by someone holding the matching private key. Your client signs the challenge locally and sends back the signature. The private key itself is never transmitted.

That last point is the whole value proposition: there is no shared secret crossing the network that an eavesdropper or a compromised server could capture and replay. A password, by contrast, is handed over on every login.

Generating a modern key

Use Ed25519. It is fast, produces short keys, and avoids the footguns of older RSA configurations:

ssh-keygen -t ed25519 -C "you@workstation"

When prompted, set a passphrase. We will come back to why. This creates two files in ~/.ssh/: id_ed25519 (private — guard it) and id_ed25519.pub (public — shareable).

Installing the public key on the server

The clean way is ssh-copy-id, which appends your public key to the server's ~/.ssh/authorized_keys with correct permissions:

ssh-copy-id you@server

If you have to do it manually, the permissions matter — SSH will silently refuse keys if they are too open:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Test it in a new terminal before you rely on it. Keep your existing session open until you have confirmed the key works.

The mistake people make: an unprotected private key

Here is the part most guides gloss over. Key authentication moves the entire security of your login onto one file: the private key. If that file is readable and unencrypted, then anyone who copies it — malware on your laptop, a careless backup, a shared machine — now is you, silently, with no password prompt to slow them down.

Two defenses, in order of strength:

  • Passphrase-encrypt the key. That is what the prompt during ssh-keygen was for. An encrypted key file is useless to a thief without the passphrase. Use ssh-agent so you only type it once per session.
  • Anchor the key to hardware. A passphrase still means the key material touches disk and RAM. A hardware-backed key keeps the private key inside a device that will not export it, so a copied file is not enough — the attacker needs the physical token.

Hardware-backed SSH keys

OpenSSH supports security keys natively. If you have a FIDO2 token, you can generate a key whose private half lives on the device:

ssh-keygen -t ed25519-sk -C "you@workstation"

The resulting key requires the physical token (and often a touch) to authenticate. A device-bound credential such as Dire Wolf takes the same idea further by anchoring the key to a TPM and refusing to export it at all. The point is identical: turn "stolen key file" back into "needs the hardware in hand."

Managing keys over time

  • Use a different key per device, not one key copied everywhere. Then losing one laptop means revoking one key, not rotating your entire identity.
  • Give each entry in authorized_keys a clear comment so you know whose key it is when it is time to remove one.
  • Remove keys when people or machines leave. Access that is never revoked is the quiet way old credentials become incidents.

What SSH key authentication protects against — and what it doesn't

It defeats password guessing and spraying entirely, and it removes the risk of a secret being captured in transit. Those are large, real wins.

It does not protect you if the private key is stolen in a usable form, if your client machine is compromised while the key is unlocked in the agent, or if stale keys are left in authorized_keys long after they should be gone. Key authentication is only as strong as the custody of the private key — which is exactly why passphrases and hardware anchoring are not optional extras but the other half of the control.

Keys are better than passwords because the secret never crosses the wire. They are only better in practice if the secret also cannot be quietly copied off your disk.