Loading...

Lab 57: tmux Sessions

Use tmux to keep multiple workflows organized and recoverable across SSH disconnects. Start a named session, detach and reattach cleanly, create and name a window for log work, 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 sessions organized and accessible if your connection drops. You decide to use tmux so you can detach, reconnect, and continue work 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.

What You’ll Practice

  • Creating a named session using tmux new -s.
  • Detaching with the tmux prefix sequence (Ctrl+b then d).
  • Listing sessions using tmux ls / tmux list-sessions.
  • Reattaching using tmux attach -t.
  • Window management basics: create window and rename window.
  • Ending a session using tmux kill-session.

Walkthrough

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

A named session makes it easy to reconnect later. In production, naming sessions after the task (“monitor,” “upgrade,” “incident”) reduces confusion.

tmux session 'monitor' started.
Step 2 : Detach from the tmux session.
Action
Ctrl+b d

Detaching keeps the session alive on the server while your SSH connection comes and goes. This is the core reliability benefit of tmux.

Detached from 'monitor' session.
Step 3 : List all tmux sessions.
Command
tmux ls
# OR
tmux list-sessions

Listing sessions confirms what is currently running and provides the exact session name to reattach.

monitor: 1 windows (created Tue Jul 23 14:00:00 2025) [80x24]
Step 4 : Reattach to the monitor session.
Command
tmux attach -t monitor

Reattaching returns you to the exact session state. This is how you resume monitoring or long-running operations without restarting processes.

Reattached to 'monitor' session.
Step 5 : Create a new window inside tmux.
Action
Ctrl+b c

Windows are separate workspaces within a session. Use them to keep monitoring, log review, and change execution separated so you can switch contexts safely.

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

Naming windows makes multi-window sessions usable under pressure. “logs” is a common convention for a window used for tailing or reviewing system messages.

Window renamed to 'logs'.
Step 7 : Kill the tmux session.
Note

This lab’s script attempts to kill the session using a window name, but kill-session -t targets a session, not a window. The correct target here is the session name: monitor.

Command
tmux kill-session -t monitor

Terminating the session explicitly prevents stale sessions from accumulating. In real environments, stale sessions can hide unfinished work and confuse future operators.

Session 'monitor' terminated.

Reference

  • tmux new -s <name> : Creates a new session with a specific name.
    • -s : Sets the session name.
  • Ctrl+b : Default tmux prefix key. Most tmux actions begin with prefix then a command key.
  • Ctrl+b d : Detaches from the current session without ending it.
  • tmux ls / tmux list-sessions : Lists existing tmux sessions.
  • tmux attach -t <name> : Attaches to a session by name.
    • -t : Targets a specific session.
  • Ctrl+b c : Creates a new window.
  • Ctrl+b , : Renames the current window.
  • tmux kill-session -t <session> : Terminates a session by name.