Using GNU Screen on a Remote Machine

Cables - source http://www.sxc.hu/photo/496858

I recently posted about using nohup to run a command, particularly on a remote machine, that keeps running even when you close the terminal or connection that started it.

Several people in the comments there also suggested GNU Screen for a similar purpose.

So, what is Screen? It describes itself as:

... a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.

Basically, among other things, it can create multiple 'virtual terminals' that run inside a single physical terminal or connection, and offers you additional features, such as resuming sessions later and basic copy and paste.

What we're interested in in the context of my other post is running commands in the background on remote machines, so I can start a command running, disconnect from SSH, but the command will stay running.

Screen, unlike Nohup, will allow me to come back later and interact directly with the terminal that I started, not just dump the results of a command to a file.

On your remote machine, start the program:

$ screen

You'll get a brief copyright notice and such, just press Space as directed. You are now running Screen (although it won't look any different to a normal terminal session by default).

Now, feel free to go off and start that important task. Once it's up and running, press Ctrl+A, then Ctrl+D. Screen sends you back to your shell and you can now disconnect.

Later, when you want to come back, run:

$ screen -r

Your old session is restored! Anything you started should still be running.

Screen is a lot more powerful than just offering this feature, however, but we'll save the rest for another day.

Finally, when you are actually done with a Screen session for good, quit it by pressing Ctrl+A, then Ctrl+\ or you can simply type exit into the terminal as normal.

[image source]

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Using GNU Screen on a Remote Machine

  1. Martin (guest)

    # Posted on 12 July 2008 at 11:46 AM

    Note that screen is not necessarily installed by default; e.g. on my Fedora 9 I had to do yum -y install screen as root.



  2. # Posted on 19 August 2008 at 08:45 PM

    [...] have covered GNU Screen for running remote commands previously, but I have not given a full beginner’s getting started guide to using the [...]



Home » Articles » Using GNU Screen on a Remote Machine