Tuesday, July 24, 2007

Keeping SSH Session Open

If you're a person that uses ssh often to connect to remote machines one thing you'll discover pretty quick is that you want a way to keep your ssh session 'open and running' when you're disconnected. The best solution I found for that is screen. To quote directly from the man for screen:

Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.
Here's a good .screenrc, just drop it in your home directory and you should be good to go.

The usual process is to log into a server, run screen and then work within the screen shells to do your work. When you're ready to log off the server just type CTL+A and then D and you should be back at the login bash/csh/whatever prompt and see [detached] above it. When you log back into the server (after logging off or being kicked off due to a connection problem) just type screen -r and you should be back into the screen session you had working before. Now that I've been using screen for almost 3 years I don't know how I ever got along without it.

No comments: