hamwaves.com
;

Persistent Remote Shells
with screen

Serge Y. Stroobandt

Copyright 2014–2022, licensed under Creative Commons BY-NC-SA

  1. Home
  2. IT
  3. Command Line
  4. 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.

Commands to evoke screen from a terminal
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:

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 commands for use within a screen session
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:

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
Creative Commons Licence
This work is licensed under a Creative Commons Attribution‑NonCommercial‑ShareAlike 4.0 International License.
Other licensing available on request.
GNU GPL v3
Unless otherwise stated, all originally authored software on this site is licensed under the terms of GNU GPL version 3.
cookie
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 employs a Python Bottle server‑side script.
This page includes an open-source client-side script, written in Python and
transcoded by Brython to make it run as secure JavaScript in the browser.
Static XHTML generated from Markdown by Pandoc and
the GNU/Linux make, sed and gpp commands.
LaTeXmath markup rendered with MathJax.
BibTeX references are best read with JabRef.
Unattended CSS typesetting with Prince.
This work is published at https://hamwaves.com/screen/en/.
profile for Serge Stroobandt on Stack Exchange, a network of free, community-driven Q&A sites
GnuPG
Use my OpenPGP public key to encrypt messages for:

echo c2VyZ2VAc3Ryb29iYW5kdC5jb20K |base64 -d
Last update: Sunday, August 21, 2022.