Loading...

Lab 57: tmux Sessions

Use tmux to keep multi-step terminal work organized and recoverable across SSH disconnects. Create a named session, detach and reattach cleanly, add a dedicated window for logs, and terminate the session when the task is complete.

core troubleshooting

Scenario

You are managing multiple long-running processes on a remote system and need a reliable way to keep work organized and accessible if your connection drops. You decide to use tmux so you can detach, reconnect, and continue without losing state.

Operator context

Terminal multiplexers are baseline tooling for remote operations. They reduce failure risk during maintenance and make it easier to separate monitoring, logs, and change execution into explicit workspaces.

Objective

  • Start a new tmux session named monitor.
  • Detach from the session without ending it.
  • List available tmux sessions.
  • Reattach to the monitor session.
  • Create a new window and rename it to logs.
  • Terminate the session cleanly.

Concepts

  • A tmux session is a persistent workspace that survives SSH disconnects.
  • Windows separate tasks inside a session, reducing mistakes during remote operations.
  • Detach keeps processes running server-side while you drop back to the normal shell.
  • Session inventory (tmux ls) is an operational check before attaching or killing anything.
  • Explicit termination prevents stale sessions and makes the end of a change unambiguous.

Walkthrough

Step 1 : Start a new tmux session called monitor.
Command
tmux new -s monitor

A named session makes reconnects predictable. Use names tied to the task to avoid attaching to the wrong workspace.

# You are now inside the tmux session.
# Start your monitoring or long-running work here.
Step 2 : Detach from the tmux session.
Action
Ctrl+b then d

Detaching leaves the session running on the server. This is the core reliability benefit of tmux during remote work.

[detached (from session monitor)]
Step 3 : List tmux sessions to confirm state.
Command
tmux ls

This inventory check confirms what is running and provides the exact session name you should target.

monitor: 1 windows (created Tue Feb 10 04:00:00 2026) [80x24]
Step 4 : Reattach to the monitor session.
Command
tmux attach -t monitor

Reattaching returns you to the exact session state so you can continue work without restarting processes.

[attached to monitor]
Step 5 : Create a new window for log work.
Action
Ctrl+b then c

A new window gives you a dedicated workspace for logs, keeping monitoring and change execution separate.

# New window created.
Step 6 : Rename the current window to logs.
Action
Ctrl+b then ,

Window names reduce mistakes when you are switching quickly. Use simple names like logs, shell, or deploy.

# Window renamed to 'logs'.
Step 7 : Terminate the session when finished.
Command
tmux kill-session -t monitor

Killing the session ends all windows and panes under it. Terminate explicitly so you do not leave stale sessions on shared systems.

# Confirm the session is gone:
tmux ls

Common breakpoints

tmux: command not found

tmux is not installed. Install it with your distro package manager and confirm it is present in PATH.

no sessions

tmux ls shows no sessions because you are listing as a different user or the session was terminated. Confirm your user and recreate the session if needed.

sessions: attach failed: session not found

The target name is wrong or the session no longer exists. Run tmux ls and attach using the exact name.

Killing the wrong session

Always inventory first. Use tmux ls before any destructive action so you do not terminate the wrong workspace.

Cleanup checklist

Ensure the monitor session does not persist after the lab.

Commands
tmux ls
# If monitor still exists:
tmux kill-session -t monitor
tmux ls
Success signal

tmux ls returns no sessions or does not list monitor.

Reference

  • tmux new -s <name> : Create a new session.
    • -s: session name
  • tmux ls : List sessions.
  • tmux attach -t <name> : Attach to a session.
    • -t: target session
  • Ctrl+b : Default prefix key.
  • Ctrl+b d : Detach from the current session.
  • Ctrl+b c : Create a new window.
  • Ctrl+b , : Rename the current window.
  • tmux kill-session -t <name> : Terminate a session.