Stop your SSH agent from forgetting your keys after every reboot

SSH & Remote Administration

Stop your SSH agent from forgetting your keys after every reboot

🧩 The Challenge

Dealing with the constant “Permission denied (publickey)” error just because you bounced your terminal is soul-crushing. I’ve wasted countless hours manually running ssh-add every single morning because I forgot to bake it into my environment.

💡 The Fix

Use the keychain tool to manage your SSH agent so it stays alive across shell sessions and reboots. It basically acts as a wrapper that hooks your running agent into every new shell you spawn.

keychain -q --eval id_rsa
source ~/.keychain/$HOSTNAME-sh

⚙️ Why It Works

Adding that snippet to your shell configuration file ensures that every time you open a new tab, the script checks if your agent is already running and simply links to it. It’s way better than hardcoding environment variables that end up stale anyway.

🚀 Pro-Tip: Stick the source line at the very bottom of your .bash_profile or .zshrc so it doesn’t get messed up by other path exports.

Linux Tips & Tricks | © ngelinux.com | 10/6/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted