Stop leaving dead SSH agent sockets hanging around
SSH & Remote Administration
Stop leaving dead SSH agent sockets hanging around
🧩 The Challenge
You know that feeling when you’ve been hopping between jump hosts all day and suddenly your local terminal stops talking to your ssh-agent? You end up with a dozen stale sockets in /tmp that keep trying to authenticate you against the wrong identity.
💡 The Fix
Just clean up the old sockets and force your shell to pick up the right environment variables with one quick command. It’ll save you from rebooting your laptop just to get git pulling again.
eval $(ssh-agent -k) && eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
⚙️ Why It Works
This chain kills the zombie agent process, spawns a fresh one, and exports the correct environment variables into your current shell session so the local tools find the socket immediately.
🚀 Pro-Tip: Stick this in your .zshrc or .bashrc as an alias like ‘fix-ssh’ and you’ll never manually hunt for a PID again.
Linux Tips & Tricks | © ngelinux.com | 10/3/2026
