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 ~.
Subscribe to:
Post Comments (Atom)
You might be interested in Keychain.
ReplyDeletehttp://www.funtoo.org/wiki/Keychain
It does a similar thing - may even be usable directly.
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.
ReplyDeleteI've also put this in a github repo: https://github.com/dagit/dotfiles
Thanks for the tip; this saved me too. I love tmux, and the symlink trick is really neat.
ReplyDeleteCan 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).
Thanks, this works great!
ReplyDeleteOne 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.