Git, containers and DevOps

Command screen

Work with terminal sessions

Linux · Bash examples · commands run on the selected server

When to use screen

Use screen to keep an interactive server workspace separate from the lifetime of an SSH connection. The session lives on that server and account; reconnect to the same host before trying to reattach.

Syntax

screen [PARAMETERS]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-S NAME
Create a named session.
-ls
List of screen-sessions.
-r NAME
Connect to a disconnected session.

Usage examples

Create a work session

screen -S maintenance

A named screen session starts, providing a persistent terminal workspace.

Show your sessions

screen -ls

Existing sessions for the account are listed.

Return to session

screen -r maintenance

The named session is reattached if its state and permissions allow it.

Notes and limitations

  • To disconnect, Ctrl+A is usually used, then D; running tasks remain in the session.
  • The utility may require separate installation. Make sure you are connecting to your own and not someone else's administrative session.

Common questions and troubleshooting

How do I disconnect without ending the session?

The usual default is Ctrl+A followed by D to detach. Exiting the shell inside the session instead can end that workspace.

Will screen survive a server reboot?

No ordinary screen session survives a reboot or account process termination. Use a service manager for workloads requiring supervised restart.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man screen.