Linux Screen Tutorial
In this Linux Screen tutorial you will learn how to install screen on CentOS, Ubuntu, and how to use Linux screen command with examples.
Official GNU Screen man pages. Or:
What is GNU Screen
Screen command in Linux or GNU Screen main purpose to multiplex single SSH terminal.
Screen is very useful program for most cases. I am always using it when SSH connection may interpreted,
- Keep active multiple SSH terminal sessions
- Keep terminal sessions alive after SSH disconnection
- Reconnect to disconnected active terminals
- Switch between terminals
Install Linux Screen
To install Screen utility package in your system:
Install Screen on Ubuntu / Debian
$ sudo apt-get update $ sudo apt-get install screen
Install Screen CentOS / RedHat
# yum install screen
To install on CentOS 8 folow guide: How To Install Linux Screen on CentOS 8
Linux Screen command examples
Creating new session
To create new terminal session press “Ctrl + a” following “c” keys combination.
Switch to next session
If you have more than session you can switch between windows using “Ctrl + a” and “n” combination.
Switch to previous session
Switch to previous screen: “Ctrl + a” and “p”
Detach from Linux Screen
“Ctrl + a” and “d” will detach from Linux screen session, but program running in the session will still run after detaching. And you will able reattach and resume session at any time.
Reattach and Resume Screen Session
To attach and resume detached session run
$ screen -r
$ screen -r ID
Where ID is session ID. In case if you have more than 1 detached screen sessions, you must enter session ID also.
List Screens or Find out Screen Session ID
To find out screen session ID’s and list screens you have to use screen -ls or:
$ screen -list
As shown on screenshot I have 2 screens with ID’s 1747 and 1693. To reattach, for example screen with ID 1747 I should type:
$ screen -r 1747
How to use Linux Screen
In next video animation you see basic usage of Screen program:
- Starting GNU Screen utility
- In new window starting htop utility
- Creating new Screen window: “Ctrl + a” following “c“
- In new window starting top utility
- Switching to next window: “Ctrl + a” and “n“
- Detaching from Linux Screen: “Ctrl + a” and “d“
- Listing Screens: screen -ls
- Reattaching and resume Screen session