mkdir -p ~/.config && touch ~/.config/ssh-agent.pid
- Paste the contents of
ssh-agent-manage.sh
into your.bashrc
or.bash_profile
or similar killall -9 ssh-agent
- Start a new terminal session (note: old sessions will not see ssh-agent, only new ones)
This snippet, when included in .bashrc
, will ensure that your session has a working ssh-agent
with all your ssh keys loaded into it. It does this without creating separate ssh-agent
processes by:
- Using
~/.config/ssh-agent.socket
as the socket, rather than a random-named temporary socket - Tracking the PID of
ssh-agent
in~/.config/ssh-agent.pid
- setting up the appropriate environment variables to point to any already-running
ssh-agent
started this way (NB: if you start an agent process by hand, this won't know about it) - starting up an
ssh-agent
if it can't find a properly-configured version already running
This will fail if the directory for
$SSH_AUTH_SOCK
doesn't exist. You'll probably only run into this error on a fresh install, or if you modify the path forSSH_AUTH_SOCK
. Worth noting you may want to add amkdir -p "$HOME/.config"
near the start of the script, with adjustments if you do modify the path, just in case.Thanks for the gist of it!