Table of Contents

Intro

On Linux, we sometimes need to check on what hashcat is doing via SSH. By default, you can't reattach to the same console terminal (tty1, tty2 etc.) that was used to start a process. However, there is a secure option for doing this called screen.

Requirements

This example will only cover Ubuntu, as it is the distribution most commonly used by beginners.

1. Download and install Ubuntu: http://www.ubuntu.com/download

2. Install the SSH client / server:

  sudo apt-get install openssh-server openssh-client

3. Install screen:

  sudo apt-get install screen

Usage

To use screen to detach from a running process, start screen before starting the process (such as a GPGPU application like hashcat). After screen starts, you enter a virtual console with its own PID. To create a new virtual terminal with a specific name in screen, enter:

screen -S [name]

To detach from a running virtual terminal, we use:

CTRL+A D

To reattach to a detached virtual terminal, assuming you have only one running:

screen -x

If running more than one virtual terminal, we need to know either its PID, or the name that you chose when invoking screen -x. If more than one screen is running, screen -x will display something like:

There are several suitable screens on:
	19814.pts-0.sl1	(09/19/11 15:28:06)	(Detached)
	12239.pts-0.sl1	(09/10/11 15:02:29)	(Detached)
	1942.name	(09/10/11 17:05:40)	(Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

By reviewing the start time, the PID, or the name of the desired terminal, we can identify the screen to be reattached. For example, if we want to reattach to the first terminal in the list above, we can either run:

screen -r 19814

or

screen -x name

Alternatives

tmux is similar to screen and has some compelling additional features.

Conclusion

Using screen not only allows you to attach to an already-running terminal, but it also eliminates the possibility of data loss or unexpected termination of your process.

If you are using an unstable connection, such as GPRS or WiMax, directly attached processes terminate when the connection drops. With screen, you can SSH back into the system and reattach to your terminal after a disconnection.