Direct answer: Keep SSH private keys off the plain filesystem. Hold them in a hardware security key or smartcard that never exports the key, or sign through ssh-agent, and back that up with passphrases, short certificate lifetimes, and prompt revocation when a machine disappears.

The most valuable file on many laptops is a few kilobytes of math in a hidden folder. A private SSH key is a complete identity, and copying it takes one line of script. The habit of leaving keys loose on disk survives from a friendlier era of computing, and it has better replacements now.

The trending query Don't keep your SSH keys on disk made the Hacker News front page in late November 2026, on a day when plenty of readers owned a machine they would rather nobody opened. The durable idea is defense in depth: assume any file can be copied, and design so that a copy alone is worthless.

Why one small file is a master key

SSH, the protocol most engineers use to log into servers, authenticates with a key pair: a public half you can share freely and a private half that must stay secret. The private half needs no password by default and carries no second factor. Whoever reads the file can log in as you on every server that trusts the key, from anywhere, until you notice and revoke it.

Attack tooling knows the location by heart. Malware that lands on a machine sweeps the ~/.ssh directory early, and a stolen laptop hands the same harvest to whoever boots it. A plain on-disk key has no second factor and no revocation speed, which turns one copied file into every door at once.

Plain key filecopied once, used foreverssh-agentaccess while session livesHardware keykey never exportedhighest riskmiddle groundstrongest

Better places to keep a key

Hardware security keys and smartcards hold the private key inside the device and refuse to export it. Signing happens on the device itself, so the server verifies a proof while the key stays put. Malware that copies files finds nothing usable, and using the key requires the physical token plus whatever PIN protects it.

The software middle ground is ssh-agent, a process that holds the decrypted key in memory and performs signatures on request. A copied disk no longer contains the key, and access lasts only while the agent session lives. From there, a sensible hardening sequence looks like this:

  1. Inventory where your keys live and which servers trust them.
  2. Move signing into an agent or a hardware key.
  3. Passphrase-encrypt anything that must remain on disk.
  4. Prefer short-lived certificates for teams and shared servers.
  5. Revoke immediately when a machine or token goes missing.
missedyour Brain mapquiz yourselfmasteredWatch your weak spots turn green.

Drop in your PDF - it doesn't leave your device.
Every miss becomes a red node on your map.
Free plan: 21 nodes, no card, no countdown.

Open Brain - free

Depth beats any single perfect defense

Defense in depth layers controls so that no single failure is fatal. Passphrase encryption keeps a stolen file unusable without a second secret. Short certificate lifetimes, certificates being temporary credentials that expire on their own, cap how long any leaked grant survives. Prompt revocation closes the door the day a machine goes missing, which is the control that actually limits damage.

Storage choiceWhat a thief walks away with
Plain file on diskThe key itself, reusable everywhere, until revoked
ssh-agentAccess for as long as the session lives
Hardware key or smartcardNothing, without the physical device and its PIN
Short-lived certificateA grant that expires on its own

A copied file is silent, while a missing object announces itself. The lesson is that hardware keys move the risk from quiet duplication to a physical token, and tokens are things you can notice are gone.

Key takeaways

  • An SSH private key is a complete identity: anyone who reads the file can log in as you everywhere the key is trusted.
  • Malware and stolen laptops harvest the ~/.ssh directory early, and plain on-disk keys have no second factor and no revocation speed.
  • Hardware security keys and smartcards hold the key inside the device, sign on the device, and never export it.
  • ssh-agent keeps the decrypted key in one protected process, so a copied disk contains nothing usable.
  • Layer passphrases, short certificate lifetimes, and prompt revocation so no single failure hands over every door.

Quick answers

Why is an on-disk key risky?
One copied file is a complete identity with no second factor; it works from anywhere until you notice and revoke it.

What does a hardware security key do differently?
The private key never leaves the device; it signs login challenges internally, so copying files yields nothing.

Is ssh-agent enough on its own?
It is a large step up from loose files, though access lasts while the session lives, so lock or restart it when you step away.

What are short-lived certificates for?
They replace long-lived keys with credentials that expire automatically, limiting how long any leak stays useful.

What matters most when a laptop goes missing?
Revoking the keys and certificates it held the same day; revocation speed is the control that limits the damage.

One thing to do tonight

List the files in your SSH directory and ask which of them could log in as you from anywhere. Then decide where that identity should live instead, and write the answer down before the next laptop walks off.