How To Use “Screen” To Keep Session Alive Upon Network Failure

February 18th, 2008

linux-logo.jpgWhen you’re working remotely on a Linux server through SSH, you are at risk of losing important data if you encounter a network failure. Worst than that, you could even end up “breaking” your Linux box or locking yourself out. Think about a critical component installation interrupted by a network problem. That could mean disaster in some cases.

Using Screen To Work Remotely

Screen is a Linux tool that allows you to keep your session alive in case your disconnected. Once you gain back remote access to your server, you can “reattach” yourself to your previous session.

So for example, if you’re compiling a huge application and you get disconnected for whatever reason, the server will keep doing its thing and you will be able to get back in there later.

How To Use Screen For Session Management

First of all, you gotta make sure you’ve got screen installed. On CentOS / RHEL, you can use Yum:

# yum install screen

Othewise you can surely find a compiled package for your distribution.

When you want to create a new screen session, simply type

# screen

Now suppose you got disconnected, once you logged back in you can list the ongoing screen sessions:

# screen -list
There is a screen on:
        14173.pts-0.clapton     (Detached)
1 Socket in /var/run/screen/S-root.

My test server is named clapton by the way…

Now to reattach to an existing session, type:

# screen -r session_number

Where as in this example the session number would’ve been 14173. And when you want to end a screen session, simply type exit.

You might also find other interesting options for screen in the man pages.

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




Webmaster Resources: Web Hosting Blog
© Copyright 2012 - TheWebHostingHero.com
Follow us on TwitterFacebookSubscribe to our RSS Feed