Resuming an Interrupted SSH Session

If you ssh into remote *nix boxes with any sort of regularity, it's almost inevitble that at some point your connection is going to drop. If it happens while you are editing a file it can be a real pain to start from where you left off. In my case, I had an account on my school's Unix server but it would kick me off after about 5-10 minutes of inactivity. Talk about frustrating. 

Fortunately, the "screen" command let's you easily restart your session. 

Get Screen

Your distro probably already has screen built in. If you're using ubuntu and it's not there just type:
sudo apt-get install screen
For gentoo the command would be:
emerge -av app-misc/screen
Using Screen

Once it's installed usage is trivial. If you're only going to be using a single session, connect via ssh and type:
screen
If you get dissconnected, reconnect your ssh session and type:
screen -R
You will then enter the session where you left off.
You can check if there is an existing screen session by typing:
screen -ls
 If you want to use multiple sessions, you will need to name the sessions with a unique name.
screen -S session1
Then connect in the same way, but including the session name:
screen -R session1
 Those are the basics! Screen has more advanced features you can check out in the man page.

No comments:

Post a Comment