Lost SSH Connection and GNU screen
by Sebastien Mirolo on Thu, 9 Sep 2010I had to do work remotely on a machine that required long session recently and the ssh connection kept dropping at random. It is very annoying and it seems almost impossible to track it down. The best explanation so far looks to lie with the way routers, firewalls and other bridges between me and the remote machine maintain some sanity into their NAT tables. In any case, I started to use GNU screen such that least running jobs do not just get killed off when the connection dropped.
There is a lot of good stuff written about GNU screen but it hardly mentioned how much it can get in the way of your command line habits. First, the backspace does not work as expected unless you configure your session accordingly. I thus added the following line to my ~/.bash_profile:
alias screen='TERM=screen screen'
I also found out this little piece of code very useful to know when I am in a screen session and when I am in raw ssh session. So I've added into ~/.screenrc:
shell -${SHELL} caption always "%n(%t) : %C"
Finally, annoying as hell, Ctrl-A is kind of the meta-used-for-everything key combination in screen. This means to go to the beginning of the line, you have to type "Ctrl-A A" to pass Ctrl-A to bash.