Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a variation of the following line:

export SSH_AUTH_SOCK=$(find /tmp/ssh-* -name agent.\* -uid $(id -u)|head -n 1)

found over at Github. This way I should be able to use my forwarded agent connection on the remote system even from inside screen or tmux. However, what if I establish two separate SSH connections to the remote machine and both of them run a separate instance of the ssh-agent?

The question boils down to:

  1. should I avoid starting another instance of ssh-agent in the first place?
  2. if the answer is no on the preceding point, how do I choose to which existing socket to connect, given there are multiple running at the moment?
  3. bonus question: can there be something like a stale socket? I.e. when I look for the socket using the find command above, can I end up with two alternatives one of which has gone bad/stale? Or are sockets cleaned up automatically when the process owning them dies? Turns out there can be stale sockets. Just had the issue.
share|improve this question
up vote 1 down vote accepted

You should avoid starting multiple ssh-agent processes in the first place. You can use a command like pgrep -u <your_username> ssh-agent to detect the PID of your ssh-agent process (or lack thereof).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .