| |

LFCS 58 ๐Ÿง Persistent Sessions โ€” nohup, screen, tmux

โฑ๏ธ Estimated read: 12 min | |

A shell session ends when the terminal closes or the SSH connection drops. Every process that was started from that shell receives a SIGHUP (hang-up signal), and unless the process is specifically designed to survive it, it terminates. This is the default behavior, and for a quick command it is correct. For a long-running taskโ€”a database migration, a compile, a training jobโ€”it is a disaster. The three tools in this chapter solve the same problem in three different ways: nohup ignores the hang-up signal so the process survives, screen and tmux are terminal multiplexers that detach the entire session from the terminal so that it can be reattached later .

The distinction between nohup and the multiplexers is the distinction between “keep this one process alive” and “keep this entire terminal session alive.” nohup is a single command wrapper: nohup command & runs the command, redirects its output to nohup.out, and makes it immune to the hang-up signal. The process continues running, but you cannot reattach to it; you can only check it with ps or read its output file . screen and tmux create a virtual terminal that persists independently of the SSH session. You attach to the session, run commands, detach, log out, and later reattach to find the session exactly as you left it, with the command still running and its output still in the scrollback buffer .

Key point: nohup command & keeps a single process alive after logout by ignoring SIGHUP, but it cannot be reattached. screen and tmux are terminal multiplexers that persist an entire session; you detach with a key sequence, log out, and reattach later to find the command still running. The LFCS exam objective is “use terminal multiplexers for persistent sessions,” and tmux is the modern choice .


Why persistent sessions matter

The SSH disconnect problem. An SSH connection is not reliable. A laptop goes to sleep, a Wi-Fi network drops, a VPN times out, and the TCP connection closes. When the connection closes, the remote shell receives SIGHUP, and every process in its session is terminated. The nohup command is the minimal fix: it makes the process ignore the signal, so the disconnect does not kill it . The terminal multiplexers are the complete fix: they detach the session from the terminal entirely, so the terminal can close without affecting the session .

The reattach problem. nohup solves the “keep running” problem but not the “see what happened” problem. The process’s output goes to a file, and the only way to interact with it is to read the file or send it signals. A multiplexer solves both: the session persists, and you can reattach to it from any terminal, on any machine, as long as you can SSH to the host. The scrollback buffer, the running command, and the shell prompt are all preserved .

The multitasking problem. A single SSH session runs one foreground command at a time. A multiplexer lets you create multiple windows and panes within the same session. You can run a compile in one pane, tail a log in another, and keep a shell prompt in a third, all within the same detached session. This is the workflow benefit that screen and tmux provide beyond persistence .

The LFCS objective. The exam blueprint includes “use terminal multiplexers for persistent sessions” under the Essential Commands domain . The official objective explicitly mentions multiplexers, which means screen or tmux is the expected tool. nohup is a related command that appears in process management contexts, but it is not a multiplexer. The LFCS practice questions include installing tmux, which is a strong signal that tmux is the expected tool .


a. nohup: the minimal persistence wrapper

nohup (no hang-up) runs a command with SIGHUP ignored. The command continues after the terminal closes, and its output is redirected to nohup.out if stdout is a terminal.

# Run a script in the background with nohup
# The & puts it in the background
# The output goes to nohup.out by default
nohup ./backup.sh &

# The shell prints the PID of the background process
# [1] 12345

# Check the output file
cat nohup.out

# Check that the process is still running
ps -p 12345

The nohup.out file is created in the current directory if stdout is a terminal. If the current directory is not writable, nohup writes to $HOME/nohup.out instead . The explicit redirect is the better practice: nohup ./script.sh > output.log 2>&1 & sends both stdout and stderr to the named file, and the & puts the process in the background.

The limitation is the interaction model. nohup does not provide a way to reattach to the process. The process is running, but you cannot see its live output, send it input, or interact with it. For a batch job that produces a log file and does not need interaction, nohup is sufficient. For an interactive process, it is not.


b. screen: the classic multiplexer

screen is the older of the two multiplexers, and it is available on most distributions, though it may not be installed by default . The session is created with screen -S name, and the detach key is Ctrl+A followed by D.

# Install screen on Debian/Ubuntu
sudo apt install screen

# Create a named session
# The -S flag gives the session a name
screen -S backup

# Inside the session, run the long command
./backup.sh

# Detach from the session
# Press Ctrl+A, then D
# The session continues running in the background

# List the sessions
screen -ls
# Output: There is a screen on:
#         12345.backup (Detached)

# Reattach to the session
screen -r backup

The screen -ls command lists the sessions and their status. A detached session can be reattached with screen -r name. If the session is attached to another terminal, screen -d -r name detaches it from the other terminal and attaches it to the current one . The Ctrl+A is the command prefix, and the D is the detach command. The prefix is configurable in .screenrc, but the default is Ctrl+A.

The session persists until the command inside it exits or the session is killed. If the SSH connection drops, the session remains detached and can be reattached later . The scrollback buffer is preserved, so the output of the command is still visible after reattachment.


c. tmux: the modern multiplexer

tmux is the newer multiplexer, and it is the one the LFCS practice materials mention. The session is created with tmux new -s name, the detach key is Ctrl+B followed by D, and the reattach command is tmux attach -t name.

# Install tmux on Debian/Ubuntu
sudo apt install tmux

# Create a named session
# The new command creates a session
# The -s flag gives it a name
tmux new -s backup

# Inside the session, run the long command
./backup.sh

# Detach from the session
# Press Ctrl+B, then D
# The session continues running

# List the sessions
tmux ls
# Output: backup: 1 windows (created Mon Oct 19 12:00:00 2026)

# Reattach to the session
tmux attach -t backup

The Ctrl+B is the prefix key, and D is the detach command. The tmux ls command lists the sessions, and tmux attach -t name reattaches . The tmux new -s name creates the session with a name, which makes the reattach command explicit.

tmux provides more than screen: it has a more consistent command set, better scripting support, and a more active development community. The tmux session can be split into panes with Ctrl+B followed by % (vertical split) or " (horizontal split), and new windows can be created with Ctrl+B followed by C . The screen equivalent is Ctrl+A followed by | or S for splits, and Ctrl+A followed by C for a new window.

The LFCS practice materials include installing tmux, and the exam objective is “use terminal multiplexers” without naming a specific one . tmux is the safer choice because it is the more modern tool and the one the practice materials reference.


Complete Example Session

The following session demonstrates nohup for a batch job, screen for a named session, and tmux for a session with panes.

# ============================================
# PART 1: nohup FOR A BATCH JOB
# ============================================
# Run the backup script in the background
# The output is redirected to backup.log
# The & puts it in the background
nohup ./backup.sh > backup.log 2>&1 &

# The shell prints the PID
# [1] 12345

# The process continues after logout
# Check the log later
tail -f backup.log
# ============================================
# PART 2: screen FOR A NAMED SESSION
# ============================================
# Create a named session
screen -S compile

# Inside the session, run the compile
make -j4

# Detach with Ctrl+A, then D
# The session continues

# List the sessions
screen -ls
# 12345.compile (Detached)

# Reattach later
screen -r compile

# The compile is still running or finished
# The scrollback shows the output
# ============================================
# PART 3: tmux FOR A SESSION WITH PANES
# ============================================
# Create a named session
tmux new -s work

# Inside the session, split the window vertically
# Press Ctrl+B, then %
# The window is now two panes

# Run the compile in the left pane
make -j4

# Run the log tail in the right pane
# Press Ctrl+B, then the right arrow key to move to the right pane
tail -f compile.log

# Detach with Ctrl+B, then D
# The session continues with both panes running

# Reattach later
tmux attach -t work

# The compile and the log tail are both still there

The three parts cover nohup for a batch job, screen for a named session, and tmux for a session with panes. What the session demonstrates is that nohup is a single-command wrapper, while screen and tmux persist an entire session that can be reattached.


Quick Reference

Tool Comparison

ToolPersistenceReattachMultiplexingDefault Install
nohupYesNoNoYes
screenYesYesYesOften
tmuxYesYesYesOften

nohup Commands

CommandEffect
nohup command &Run in background, ignore SIGHUP
nohup command > file 2>&1 &Redirect output explicitly

screen Commands

CommandEffect
screen -S nameCreate named session
Ctrl+A, DDetach
screen -lsList sessions
screen -r nameReattach
screen -d -r nameDetach from other terminal and reattach

tmux Commands

CommandEffect
tmux new -s nameCreate named session
Ctrl+B, DDetach
tmux lsList sessions
tmux attach -t nameReattach
Ctrl+B, %Split vertically
Ctrl+B, "Split horizontally
Ctrl+B, CNew window

Best Practices

โœ… Do This:

# Use nohup for simple batch jobs
nohup ./backup.sh > backup.log 2>&1 &

# Use tmux for interactive sessions
tmux new -s work

# Always name the session
tmux new -s compile

# Use tmux ls before attaching
tmux ls

โŒ Don’t Do This:

# Run a long job without nohup or a multiplexer
./backup.sh # dies on SSH disconnect

# Forget to detach before logout
# The session stays attached and the terminal is killed

# Use screen without installing it
screen -S work # command not found

Common Pitfalls

PitfallWhy It HappensFix
Job dies on logoutNo nohup or multiplexernohup or tmux
Cannot reattachSession was not detachedDetach before logout
screen not foundNot installedapt install screen
tmux not foundNot installedapt install tmux
nohup.out in wrong directorystdout not redirectedRedirect explicitly

Real-World Examples

1. nohup batch job

nohup ./migrate.sh > migrate.log 2>&1 &

2. Create screen session

screen -S backup

3. Detach screen

# Ctrl+A, then D

4. Reattach screen

screen -r backup

5. Create tmux session

tmux new -s compile

6. Detach tmux

# Ctrl+B, then D

7. Reattach tmux

tmux attach -t compile

8. Split tmux pane

# Ctrl+B, then %

9. List tmux sessions

tmux ls

10. List screen sessions

screen -ls

Visual

nohup Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  nohup command &                             โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  Process ignores SIGHUP                      โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  SSH disconnects โ†’ process continues         โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  Output in nohup.out or redirected file      โ”‚
โ”‚  No way to reattach                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

screen/tmux Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  screen -S name / tmux new -s name           โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  Virtual terminal created                    โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  Detach (Ctrl+A,D / Ctrl+B,D)                โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  SSH disconnects โ†’ session continues         โ”‚
โ”‚         โ”‚                                    โ”‚
โ”‚         โ–ผ                                    โ”‚
โ”‚  Reattach (screen -r / tmux attach)          โ”‚
โ”‚  Session is exactly as left                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Prefix Keys

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  screen: Ctrl+A                              โ”‚
โ”‚  tmux:   Ctrl+B                              โ”‚
โ”‚                                              โ”‚
โ”‚  Detach: prefix + D                          โ”‚
โ”‚  New window: prefix + C                      โ”‚
โ”‚  Split: prefix + % or "                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
nohupIgnore SIGHUP, no reattach
screenMultiplexer, Ctrl+A prefix
tmuxMultiplexer, Ctrl+B prefix
Detach (screen)Ctrl+A, D
Detach (tmux)Ctrl+B, D
Reattach (screen)screen -r name
Reattach (tmux)tmux attach -t name
LFCS objectiveUse terminal multiplexers

Key takeaways:

  • nohup keeps a single process alive but cannot be reattached. It ignores SIGHUP, redirects output to nohup.out, and continues after logout. The interaction is limited to reading the output file and sending signals .
  • screen and tmux persist an entire session. You attach, run commands, detach, log out, and reattach later to find the session exactly as you left it .
  • tmux is the modern choice. It has a more consistent command set, better scripting, and more active development. The LFCS practice materials reference installing tmux .
  • The prefix keys are different. screen uses Ctrl+A, and tmux uses Ctrl+B. The detach command is D in both, but the prefix is the first thing to remember.
  • The LFCS objective is “use terminal multiplexers.” The exam expects screen or tmux, not nohup, because nohup is not a multiplexer .
  • nohup is still useful for batch jobs. A migration script that produces a log and does not need interaction is a good fit for nohup. An interactive process or a session that must be reattached is a good fit for a multiplexer.

Remember: A persistent session is a session that survives the terminal that started it. nohup is the minimal tool: it makes a single process ignore the hang-up signal, but it does not provide a way to reattach. screen and tmux are the complete tools: they create a virtual terminal that persists independently of the SSH connection, and they let you reattach to it later. The LFCS exam expects you to know the multiplexers, and tmux is the modern choice. The pattern is always the same: create a named session, run the command, detach, log out, reattach, and find the command still running.


Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!