- mkdir -p ~/.config && touch ~/.config/ssh-agent.pid
- Paste the contents of ssh-agent-manage.shinto your.bashrcor.bash_profileor 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.socketas the socket, rather than a random-named temporary socket
- Tracking the PID of ssh-agentin~/.config/ssh-agent.pid
- setting up the appropriate environment variables to point to any already-running ssh-agentstarted this way (NB: if you start an agent process by hand, this won't know about it)
- starting up an ssh-agentif it can't find a properly-configured version already running
@soundlake -- newer versions of
ssh-addon macOS have deprecated-Ain favor of--apple-load-keychain; you can either swap that out or addexport APPLE_SSH_ADD_BEHAVIOR=macosto your environment