Persistent Remote Shells
with screen
Serge Y. Stroobandt
Copyright 2014–2022, licensed under Creative Commons BY-NC-SA
- Home
- IT
- Command Line
- screen
Connecting with ssh
Connect to the remote host computer using ssh
:
$ ssh username@hostname.url:port
Evoking screen
Screen sockets and screen sessions are one and the same thing. By default, screen sessions are named according to the scheme pid.tty.hostname
. Here are a number of commands to evoke screen
from a normal shell.
command | function |
---|---|
$ screen -S sessionname |
Start a new screen session with a given name and attach to it. |
$ screen -ls |
Lists all existing screen sessions. |
$ screen -r |
Reattach* this terminal to the only existing screen session. |
$ screen -r -S sessionname |
Reattach* this terminal to an existing screen session by name. |
$ screen -r ttynumber |
Reattach* this terminal to an existing screen session by tty number. |
$ screen -S oldsessionname -X newsessionname |
Rename a screen session. |
$ screen -S sessionname -X quit |
Kill the specified screen session by executing quit . |
Note:
- * If there exists only one screen session, it is not necessary to specify any name; just type
screen -r
at the command line.
Within a session
All commands that can be issued within a screen session start by hitting the Ctrl+A key combination, followed by another keystroke.
keystroke sequence | function |
---|---|
Ctrl+A ? |
Show the help screen. |
Ctrl+A d |
Detach* the current screen session from this terminal. The screen session and its processes remain in existence. |
Ctrl+A c |
Create a new window and switch to it. |
Ctrl+A C |
Clear the screen. |
Ctrl+A K |
Kill the current window. |
Ctrl+A p |
Go to the previous screen. |
Ctrl+A n |
Go to the next screen. |
Ctrl+A # |
Go to a specific screen number. |
Ctrl+A " |
Select a screen from a list using the arrow keys. |
Ctrl+A S |
Split the current window in half horizontally. |
Ctrl+A | |
Split the current window in half vertically. |
Ctrl+A Tab | Cycle through window regions. |
Ctrl+A X |
Eliminate a window split. |
Ctrl+A H |
Log the current screen sessions in logfiles called screenlog.n where n is the number of the screen session. |
Ctrl+A h |
Create a screenshot of the current window in a file called hardcopy.n . |
Ctrl+A x |
Lock the screen session with the password of the current user. |
Ctrl+A Esc | Enter the copy and scrollback mode. |
Esc | Leave the copy and scrollback mode. |
Note:
- * Closing the
ssh
connection also results in a detachment of the screen session. - Typing
exit
at the command line of a screen session will destroy that screen session.
Where am I?
Experiencing an Inception moment? Of course, you can always hit Ctrl+A ?
and see if you get the screen
help information. Another way is to let the environment variable $TERM
tell you what terminal type you are currently employing.
Inside a screen
session:
$ echo $TERM
screen.xterm-256color
Inside a normal terminal:
$ echo $TERM
xterm-256color
5
This work is licensed under a Creative Commons Attribution‑NonCommercial‑ShareAlike 4.0 International License.
Other licensing available on request.
Unless otherwise stated, all originally authored software on this site is licensed under the terms of GNU GPL version 3.
This static web site has no backend database.
Hence, no personal data is collected and GDPR compliance is met.
Moreover, this domain does not set any first party cookies.
All Google ads shown on this web site are, irrespective of your location,
restricted in data processing to meet compliance with the CCPA and GDPR.
However, Google AdSense may set third party cookies for traffic analysis and
use JavaScript to obtain a unique set of browser data.
Your browser can be configured to block third party cookies.
Furthermore, installing an ad blocker like EFF's Privacy Badger
will block the JavaScript of ads.
Google's ad policies can be found here.
This page includes an open-source client-side script, written in and
transcoded by to make it run as secure JavaScript in the browser.
transcoded by to make it run as secure JavaScript in the browser.
Unattended CSS typesetting with .
This work is published at https://hamwaves.com/screen/en/.
Last update: Sunday, August 21, 2022.