## 30 March 2012

### tmux + ssh-agent

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.

Step 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

Step 2. Add these two lines to your .tmux.conf:

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 ~.

#### 4 comments:

1. You might be interested in Keychain.
http://www.funtoo.org/wiki/Keychain
It does a similar thing - may even be usable directly.

2. I realized today that if I drop the quotes around the path to .ssh/ssh_auth_sock that I can use ~/.ssh/ssh_auth_sock, which is way more portable.

I've also put this in a github repo: https://github.com/dagit/dotfiles

3. Thanks for the tip; this saved me too. I love tmux, and the symlink trick is really neat.

Can you update the gist in the post to not have quotes around the path? Meanwhile, I'll remove the quotes in my .tmux.conf. +1 for portability. I was kind of uneasy about having to remember to fix the file every type (because I keep this in Git so I can use it across machines).

4. Thanks, this works great!

One note that may be helpful to others. I had to explicitly set "ForwardAgent yes" in the SSH client config of my desktop and "AllowAgentForwarding yes" in the SSH server config on the tmux server.