I found this information somewhere on StackOverflow but I forgot exactly where. I'm paraphrasing what I learned here, for future reference.
SSH uses a Unix socket to communicate with other processes. The socket's path can be found by looking at the environment variable $SSH_AUTH_SOCK
. When you re-connect to a tmux session that was started during a previous SSH session, this variable will contain the path of the previous SSH auth socket, and this will cause processes that try to connect to your authentication agent to fail. To fix this, we have to
- Create a symlink from the auth socket to a fixed path somewhere, so that we can refer to it later on, and not to modify the symlink if current is still alive. In
~/.ssh/rc
, add
if [ ! -S ~/.ssh/ssh_auth_sock ] && [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi