Terminal multiplexing and SSH

Wed
Feb 15
2012

Tools like tmux and screen are fantastic for doing work on remote systems: you can open up multiple sessions, fire off jobs, disconnect, and come back later, and things are still as you left them. However, if you use ssh-agent for credential forwarding, you've probably noticed a downside: after disconnecting and reconnecting, the environment variables that ssh and friends use to figure out how to talk to ssh-agent are now wrong.

There's a million different ways to solve this; here's my take on it:

Adding this to your .bash_profile (or .bashrc, depending on your local setup) will add aliases for both tmux and screen, which will save the four SSH-related environment variables you'll want to override inside of your terminal multiplexor to a file in your home directory. It also adds aliases for ssh, scp, and sftp, which forces the saved variables to be loaded prior to execution.

Permalink - Posted at 10:30 AM
, , , , ,
blog comments powered by Disqus