SSH + Screen How-To

Basics for this how-to:

First off, I assume you have a user account on a primary computer, and a computer you want to log into.

What is a terminal?

In linux you may use xterm, gnome-terminal, konsole, aterm, Eterm, etc, they are all "terminals" which bring you to a command line (shell) that might look something like this:

elizabeth@hour ~ $

This is where you can type in commands, move and modify files, launch programs, and even do text-based system administration, anything you need to do on your system (graphical tools that you might use simply make everything you do in a terminal easier for new users).

What is ssh?

From Wikipedia:

Secure shell or SSH is both a computer program and an associated network protocol designed for logging into and executing commands on a networked computer.

This means that you can connect to a computer in another room, or on the other side of the planet and have access to its files.

What is irssi?

A text-based chat client. In this how-to I am using it as an example of a program you might want to run in screen.

What is screen?

This is a bit difficult to explain (and why I wrote this how-to!). It's a program that you invoke to run other programs inside of. You don't necessarily see the screen program itself, you just see the program you started within it.

Now let's begin!

Let's say I have a network that looks like this:

hour and r2d2 exist on the same network. hour is a normal computer that I have a monitor attached to, keyboard, mouse, speakers, etc. r2d2 is a server, which only has a power cord and a network cable. How do we do things on r2d2?

First, open up a terminal on hour:

elizabeth@hour ~ $

now we want to type a command:

elizabeth@hour ~ $ ssh elizabeth@r2d2

ssh is the program I am using, elizabeth is the user I want to log into on r2d2, and r2d2 is the hostname (or IP #) of the computer I want to log into.

it will then prompt me for my password


Keep in mind that it will not show astricts for your password, or move the cursor at all to indicate how many characters you type, this is a security feature.

Now I am at a command prompt that looks like this:

elizabeth@r2d2 ~ $

Notice that the "hostname" section has changed from hour to r2d2, I'm now logged in to r2d2!

Now that you're in r2d2, you can do anything you need to from the command line. list files, move files, and start text-based programs (there is even graphical program support over ssh, but that is beyond the scope of this how-to). I am using irssi in this example.

elizabeth@r2d2 ~ $ irssi

This launches an irssi session (for more information on using irssi, see my irssi Basics page).

Now, there is an easy way to put this program in the background without using any additional programs: hold down Control and hit z. This will put your program in the background and put you back at the command line, like this:

elizabeth@r2d2 ~ $ irssi

[1]+ Stopped irssi
elizabeth@r2d2 ~ $

To get it back you do:

elizabeth@r2d2 ~ $ fg

Neat huh? This is a very useful technique. The only problem is that the program is killed if you log out of or somehow lose your connection to r2d2. The solution? Use screen!

The basic idea behind the screen program is similiar to the control+z/fg method, you run programs in the "background" but it has a few key differences

  1. You can log out of the machine and your program will still be running
  2. You need to start screen when you start your program
  3. You have many more options with screen, including running multiple windows inside it and splitting screens

Starting a program with screen:

elizabeth@r2d2 ~ $ screen irssi

This launches an irssi session within screen. You won't notice anything special about your irssi session, there is no indication that it's running in screen. To put screen in the background (screen calls this "detatching") you hold down Control and hit a d.

When you hit Control a d you will be put back to the normal command line. It'll look something like this:

elizabeth@r2d2 ~ $ screen irssi
elizabeth@r2d2 ~ $

To get back to the program you detatched from you would:

elizabeth@r2d2 ~ $ screen -r

Voila! You are now using screen on a remote computer.