Stop your SSH keys from getting stuck in memory forever
SSH & Remote Administration
Stop your SSH keys from getting stuck in memory forever
🧩 The Challenge
Dealing with shared jump boxes is a nightmare when your identity is lingering in an agent session that you forgot to close. It’s an easy way to leave a door wide open for whoever logs in next.
💡 The Fix
You can set a strict lifetime on your keys the moment you add them to the agent. This way, the agent nukes the identity automatically after a few hours so you don’t have to worry about it.
ssh-add -t 4h ~/.ssh/id_rsa
⚙️ Why It Works
Adding the -t flag tells the agent to keep that specific key active only for the duration you specify, then purge it from the cache. It’s a clean way to ensure your credentials aren’t just sitting there waiting to be abused.
🚀 Pro-Tip: Use ssh-add -l to see what keys are currently loaded and how much time they have left before they expire.
Linux Tips & Tricks | © ngelinux.com | 9/26/2026
