tmux + ssh-agent

Posted on March 30, 2012, in ssh, tmux, imported

Lately I’ve been using tmux on remote servers. This allows me to maintain task-specific sessions on remote servers, regardless of what computer I work from or if my internet connection get severed.

The biggest wrinkle in my setup has been ssh-agent forwarding. When I reconnect the remote side no longer knows where to find SSH_AUTH_SOCK. I found a solution.

1. On the remote host, create $HOME/.ssh/rc, make it executable, and add the following contents: Don’t forget: chmod 755$HOME/.ssh/rc

A few things kept me from getting this working straight away. You have to disable the default behavior of updating SSH_SOCK_AUTH (that’s what the first line does), then you have to set SSH_SOCK_AUTH to point at the symlink created by the script in step 1.

Edit: I mistakenly thought previously that you have to use an absolute path to the symlink because tmux won’t expand “\$HOME”or “~”. Turns out, if you don’t quote the path then tmux can do the right thing with ~.