Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.