Getting Started with tmux - Terminal Multiplexing Basics

Getting Started with tmux - Terminal Multiplexing Basics

What You'll Learn

  • Keep work running on a remote server even when SSH disconnects using tmux
  • Understand the three-layer model: sessions, windows, panes
  • Get comfortable with prefix-key combos starting with Ctrl+b
  • Detach (step away) and attach (return) freely without losing state
  • Split a single terminal screen to run multiple tasks in parallel

Target Audience: Anyone who does SSH work on remote servers and has lost progress to a flaky connection, or anyone tired of opening only one terminal at a time.

Introduction: The Day Lina Lost Her Logs

Lina: Linny-senpai, I just lost a long-running log collection on a remote server! My Wi-Fi blipped for one second, the SSH died, and now I have to start over...
Linny-senpai: Ah, the classic SSH heartbreak. You can prevent that with tmux.
Lina: tmux? Is that a new tech gadget?
Linny-senpai: It's a "terminal multiplexer." Think of it as "saving your screen on the server side." Even if your connection drops, the tmux session keeps running on the server. When you reconnect, you can pick up right where you left off.
Lina: That's amazing! How does it work under the hood?
Linny-senpai: A tmux server runs as a separate process from your SSH connection, holding the terminal state for you. SSH can die — tmux doesn't care. Today we'll learn it in three layers: (1) sessions, (2) windows, (3) panes.

The Practical Pattern

  • Before long jobs, enter tmux first (this alone kills 90% of SSH accidents)
  • To step away: Ctrl+bd (detach)
  • To return: tmux attach — your screen is back
  • More screens? Use windows (Ctrl+b c)
  • Split current screen? Use panes (Ctrl+b % / Ctrl+b ")

1. Install tmux

Lina: Doesn't tmux come pre-installed?
Linny-senpai: Depends on the distro. Always check first — that's a good habit.

Check the Version

$ tmux -V
tmux 3.4

If you see "command not found," you need to install it.

Ubuntu / Debian

$ sudo apt update
$ sudo apt install tmux

CentOS / RHEL / Rocky Linux

$ sudo dnf install tmux

No root access? On shared servers where sudo isn't allowed, ask the admin. Don't drop random binaries into /usr/local/bin/ without checking the policy first.

2. Your First tmux Session

Linny-senpai: Once installed, just type tmux and hit Enter. Nothing else.
Lina: That feels a bit scary...
Linny-senpai: Don't worry, Ctrl+b → d always gets you out safely. Remember just that escape hatch and you can't get lost.

Open a Session

$ tmux

You'll see a green status bar appear at the bottom. That's your visual proof that you're inside tmux.

[0] 0:bash*                                              "hostname" 14:00 23-May-26

Try Some Commands

Inside, it's just a regular shell. Try running anything.

$ echo "running inside tmux"
$ pwd
Lina: It looks just like a normal terminal?
Linny-senpai: That's the point — visually identical. The difference is "this screen lives on the server." Next, let's detach to feel it for real.

3. Detach and Attach - tmux's Killer Feature

Linny-senpai: Time for the main event: detach (step away) and attach (return).
Lina: "Detach" sounds intimidating...
Linny-senpai: Just a word. Think of it like closing your laptop lid but your apps keep running. Try it once and it clicks immediately.

Detach: Ctrl+b → d

While inside tmux, press these keys in sequence:

Ctrl+b
d

The green status bar disappears and you're back to your regular terminal.

[detached (from session 0)]
$

Important mental model: You didn't close it, you stepped away. On the server side, the tmux session is still alive and well.

List Sessions

$ tmux ls
0: 1 windows (created Fri May 23 14:00:00 2026)

Session 0 is still there. Alive and waiting.

Attach: Come Back

$ tmux attach

Your screen comes back exactly as you left it. Command history, open files, running processes — all preserved.

Lina: Wait, this is genuinely moving! Is "SSH disconnect is no longer scary" really just this?
Linny-senpai: Yes. The real-world workflow is: SSH in, then immediately tmux. Wi-Fi drops? Close your laptop? Doesn't matter — the tmux session keeps living. SSH back in later, tmux attach, and resume like nothing happened.

Common confusion: Typing exit in the shell destroys the session. To step away you must use Ctrl+b → d (detach). exit closes the session, and tmux attach won't bring it back.

4. What Is a Prefix Key?

Lina: You keep saying "Ctrl+b" — what exactly is that?
Linny-senpai: It's the signal that tells tmux "the next key is for you, not the shell." We call it the prefix key, and it defaults to Ctrl+b.
Lina: I see — normal keys go to the shell inside, but keys after the prefix go to tmux itself.
Linny-senpai: Exactly. After Ctrl+b, d means "detach," c means "new window," and so on. The prefix is how tmux avoids stealing every keystroke from your shell.

The Prefix Pattern

Ctrl+b → some key

Ctrl+b is not held down. Press and release Ctrl+b, then press the next key.

The five prefix commands worth memorizing first

Keys Action
Ctrl+b d Detach
Ctrl+b c New window
Ctrl+b n Next window
Ctrl+b % Split pane vertically
Ctrl+b " Split pane horizontally

5. Windows: Switching Between Screens

Linny-senpai: Inside a session, tmux has a concept called "windows" — think browser tabs.
Lina: So one session can hold multiple tabs?
Linny-senpai: Exactly. "Tab 1 tails the log, tab 2 edits config, tab 3 runs a build" — you can split your mental focus cleanly.

Create a New Window

Ctrl+b
c

c is for create. A fresh window opens and you switch to it.

The status bar now shows:

[0] 0:bash- 1:bash*

Two windows: 0 and 1. * marks where you are; - marks the last one you visited.

Switch Between Windows

Ctrl+b n   # Next window
Ctrl+b p   # Previous window
Ctrl+b 0   # Jump to window 0
Ctrl+b 1   # Jump to window 1

Close a Window

Type exit in that window's shell. Or use Ctrl+b & (asks for confirmation).

6. Panes: Splitting One Screen

Lina: Windows make sense! But "splitting the screen" is something different?
Linny-senpai: Right — that's panes. They divide a single window into side-by-side regions. Tail a log on the left while you edit a file on the right, all visible at once.

Split Vertically (Left and Right)

Ctrl+b
%

The screen splits with a vertical line — two panes, left and right.

Split Horizontally (Top and Bottom)

Ctrl+b
"

The screen splits with a horizontal line — two panes, top and bottom.

Memory trick:

  • % looks like a vertical bar → vertical split (left/right)
  • " looks like a horizontal mark → horizontal split (top/bottom)

Many people find these backward at first. The key shape is the easiest mnemonic.

Move Between Panes

Ctrl+b ←   # Move to the left pane
Ctrl+b →   # Move to the right pane
Ctrl+b ↑   # Move to the upper pane
Ctrl+b ↓   # Move to the lower pane
Ctrl+b o   # Cycle through panes

Close a Pane

Type exit in that pane, or press Ctrl+b x (asks for confirmation).

7. Common Beginner Pitfalls

Lina: Senpai, what mistakes do beginners typically make?
Linny-senpai: Three to watch for. Knowing these covers most of the first-month landmines.

Pitfall 1: Holding Ctrl+b Down

Symptom: The key after the prefix does nothing, or behaves oddly.

Cause: You're still holding Ctrl+b when pressing the next key.

Fix: Press Ctrl+b, release it, then press the next key.

Pitfall 2: Running tmux Inside tmux

Symptom: The status bar doubles up; prefix keys feel "off" (intercepted by the outer tmux).

Cause: You accidentally typed tmux in a shell that was already inside tmux.

Fix: exit the inner session, or detach completely and run tmux ls to inspect what's there.

Pitfall 3: Killed the Session with exit

Symptom: tmux attach says "no sessions."

Cause: You typed exit thinking you were "stepping away," but exit destroys the session.

Fix: There's no undo. Next time, use Ctrl+b → d to detach instead.

8. The Production Template: Protect SSH Work with tmux

Copy-paste safe pattern

# 1. SSH into the server
ssh user@server

# 2. Immediately enter tmux (attach if a session exists, otherwise create)
tmux attach || tmux

# 3. Do your work normally (long log tailing, builds, backups, etc.)
tail -f /var/log/syslog
# ...

# 4. To step away: Ctrl+b → d (detach)
# 5. Now SSH can die safely - the session lives on the server

# 6. To return: SSH back in, then
tmux attach

This one pattern eliminates the majority of SSH-related work loss.

Mini Challenges - Get Hands-On

Linny-senpai: Knowledge sticks only when you move your fingers. Try these.

Challenge 1: Open a Session, Detach, Reattach

$ tmux
# → you're inside tmux now

$ echo "test"

# Press Ctrl+b → d to detach

$ tmux ls
# → confirm the session is still alive

$ tmux attach
# → your screen returns

Challenge 2: Create Two Windows and Switch Between Them

$ tmux

# Ctrl+b c to create window 1
# Ctrl+b 0 to jump to window 0
# Ctrl+b 1 to jump to window 1
# Ctrl+b n to cycle to the next

Challenge 3: Split One Window into Panes

$ tmux

# Ctrl+b % to split vertically
# Ctrl+b " to split horizontally
# Ctrl+b arrow-keys to move between panes
# Run different commands in each pane (e.g., top, df -h, tail -f /var/log/syslog)
Lina: I did it! Watching multiple data streams side-by-side feels amazing.
Linny-senpai: Right? Once your eyes get used to it, going back to single-pane terminals feels limiting. From here, look into named sessions and customizing ~/.tmux.conf.

Today's Three-Line Summary

  • tmux to enter, Ctrl+b → d to leave, tmux attach to return — this trio eliminates SSH disconnect disasters
  • The prefix key (Ctrl+b) followed by a command key is the rhythmic core of tmux operation
  • Keeping the session > window > pane hierarchy in mind unlocks dramatically more efficient parallel work

Next Reading

Lina: I've got the basics! What should I learn next?
Linny-senpai: Three directions. (1) For monitoring long-running processes: Process Management Basics with top and kill. (2) For moving files between servers: scp vs rsync. (3) If terminal fundamentals still feel shaky, pwd, cd, and ls Basics is a safe place to revisit.
Lina: Thanks to tmux, the fear of "losing my work" is finally gone!
Linny-senpai: As long as you do SSH work, tmux will pay you back daily. Use it every day until it's muscle memory.