Skip to main content

Using Screen

ThisNormally if you leave an SSH session, everything that is running will get killed. If you want to have a quickprocess overviewcontinue onto howrun you will need to use screena toprogram keeplike processesscreen. This will create a persistent session that stays running even ifafter you log out of your ssh session

Commands

Launching a Screen Session

To launch a screen session run:

screen -S <name>
# Example
screen -S project1

The name can be whatever you want as long as there is no spaces. You will use this to identify and reconnect to your session at a later time.

After hitting enter it will look like a normal command line, go ahead and run whatever long process you were going to here

Detaching From a Screen Session

After running your program, you will probably want to detach from the SSHscreen session to do other things. The easiest way is to just close your ssh window.

To detach the session press ctrl + a, let go of the keys and then press d. This will send you back to your normal ssh session.

NOTE: Do not updatetype thisexit page.or Thislogout pagein isa softscreen linkedsession until you are ready to end the screen session. IT - Sysadminexit >and Linuxlogout >will Usingcause screen to terminate and take you back to the normal ssh session.

Exiting Screen Sessions

As stated above, to terminate the screen session and all commands running within it type exit or logout. IfScreen youwill exit and kill any processes running in it.

Listing Your Active Screen Sessions

You may want to changesee what sessions you have active. To do this run:

screen -ls

In the contentsexample below I have 2 screen sessions. One named test, and one named project1:

[amdhome@mercury ~]$ screen -ls
There is a screen on:
        9955.test       (Detached)
        9971.project1   (Detached)
1 Socket in /var/run/screen/S-amdhome.

Reattaching to a Screen Session

To reattach to your screen session run:

screen -r <name>
# Example
screen -r project1

This should take you back to your screen session

Scrolling in a screen window

Sometimes you need to scroll up in a screen window, but screen won't let you by default.

To scroll press ctrl + a let go of thisthe page,keys pleaseand changethen itpress onesc. thatYou pageshould instead.now be able to scroll with your arrow keys


{{@31}}