SSH and screen, better together
I've just recently put some pieces together in my head, and have found this to be a very useful invocation to run in a Terminal window on my PowerBook:
while [ 1 ]; do ssh -t home '/usr/sbin/screen -R work'; done
(Update: Thanks to a comment by Leland Johnson, I've realized that the above just poorly reinvents autossh. Use it instead.)
Behind the scenes, here's what's up:
homeis a host defined in my
workis a persistent
screensession I have running there;
sshis key for making
- I have several forwarded ports set up to enable things like IRC and sometimes HTTP proxied through a home machine;
- I have ssh-agent running in order to ensure I never have to enter a password;
whileloop runs forever, so that whenever my
sshconnection drops—say when I go from home to work or vice versa—it gets reestablished as soon as possible.
The end result is that I always have a window with a few shells open on a machine at home, as well as a slew of ports tunneled to machines back home to provide a rough sort of VPN. The connection is usually reestablished and waiting by the time I've gotten settled and get around to visiting that window.