Sharing SSH agent between multiple shells

If you're logged in with multiple shells on a machine and want to reuse the SSH agent between them, there's an easy way that doesn't involve anything but a line of BASH.

In your first shell, run ssh-add as normal to add the keys you need:

$ ssh login.example.com
$ ssh-add

Then, in the other shell(s), re-use the SSH agent from the first shell with:

$ ssh login.example.com
$ export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name "agent.*" -user "$(whoami)" | tail -n 1)

Nice, secure and simple.


~ /home 🏠 ~ talks 💬 ~ bash ~ craftsmanship ~ db ~ dongxi ~ emacs ~ escenic ~ iam ~ java ~ js ~ language ~ latex ~ ldap ~ life ~ linux ~ llm ~ mac-os-x ~ mt-foo ~ network ~ norsk ~ python ~ quotes ~ running ~ security ~ travel ~ unix ~ various ~ vcs ~ webdesign ~ windows ~ discoveries ~ cv 🧙 ~

Licensed under CC BY Creative Commons License ~ 📡 RSS feed ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@hachyderm.io ~ 🎥 youtube.com/@skybert