Getting Started with tmux - Terminal Multiplexing Basics

Getting Started with tmux - Terminal Multiplexing Basics

What you'll be able to do

  • Set up a workspace with tmux that survives an SSH disconnect
  • Explain the three layers: session, window, and pane
  • Pause work with detach and resume it later with attach

Prerequisites (read these first)

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 terminalAn interactive program that reads the commands you type and runs them. 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: So you were working over SSH. SSH is the mechanism for connecting securely from your own machine to a computer somewhere else — also called a remote connection.
Linny-senpai: And that kind of accident is exactly what tmux prevents.
Lina: tmux? Is that a new tech gadget?
Linny-senpai: It's a "terminal multiplexer." A multiplexer is simply a tool that holds many screens inside one screen.
Lina: Many screens inside one?
Linny-senpai: Right. And those screens can stay on the server. Your connection may drop, but the screens stay put. Reconnect and you pick up right where you left off.
Lina: That's amazing! How does it work under the hood?
Linny-senpai: A separate program called the tmux server holds the screen contents for you. It runs apart from your SSH connection. SSH can die — the tmux server keeps going.
Linny-senpai: Today we'll learn three words in order: (1) session, (2) window, (3) pane.

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 ")

Learn the escape hatch first

tmux changes how your screen looks. That is why beginners often feel trapped. When in doubt, these three moves get you out.

Stuck state How to get out
Lost inside tmux Press Ctrl+b, release it, then press d (detach)
Want your screen back after detach tmux attach
Not sure whether you are inside Run echo $TMUX — any output means you are inside tmux.

Ctrl+bd always works. Those two keystrokes bring you back to your normal terminal.

And if you do destroy a session, only the screen is gone. Saved files stay right where they are, so experiment calmly.

1. Install tmux

Conclusion: tmux is not always preinstalled; check with tmux -V and install via apt or dnf.

Lina: Doesn't tmux come pre-installed?
Linny-senpai: Depends on the distro — short for distribution, meaning a flavor of Linux such as Ubuntu or CentOS. 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

Can't install it? On shared servers, sudo (the mechanism for running a command as the administrator) is often unavailable. In that case don't install it yourself — ask the server administrator.

2. Your First tmux Session

Conclusion: Just type tmux to start a session; the green status bar confirms you are inside.

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.

What a session is

A session is one workspace that tmux keeps for you. Think of reserving one table at a cafe. You can leave your things (running commands) on the table. Step away and your things are still there when you return.

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. A shell is the program that takes the commands you type and runs them — bash and zsh are the common ones. 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

Conclusion: Detach with Ctrl+b d, return with tmux attach; the session lives on the server.

Linny-senpai: Time for the main event: detach and attach.
Lina: "Detach" sounds intimidating...
Linny-senpai: It's only the word that sounds scary. Detach means "step away from the table." Attach means "come back to it."
Linny-senpai: Think of leaving your house. You turn off the lights, but the room is still there. Detach works the same way: the screen stays on the server.

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. After that you just work normally.
Linny-senpai: Wi-Fi drops? Close your laptop? The tmux session keeps living. SSH back in later, run tmux attach, and resume like nothing happened.

Lina's Mistake: Destroying a Session with exit

Lina: Senpai, trouble! I typed exit to step away, and now tmux attach says "no sessions". Where did my work go?
Linny-senpai: I'm sorry to say it's gone. exit is the command for closing a session. It is not the same as detaching.
Lina: But they looked the same to me...!
Linny-senpai: Here's the easy way to tell them apart. Ctrl+bd steps away from the table. exit folds the table up. From today, save exit for when you are truly done.
Lina: So "leaving" and "closing" are different things. I'll drill Ctrl+bd into my fingers!

Common confusion: Typing exit in the shell destroys the session. A destroyed session cannot be brought back by tmux attach. The only way to step away is Ctrl+b → d (detach).

4. What Is a Prefix Key?

Conclusion: The prefix key (Ctrl+b) signals tmux: release it, then press the command 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 — prefix simply means "something placed in front." 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

Conclusion: Windows are like browser tabs: create with Ctrl+b c, switch with n/p/numbers.

Linny-senpai: Inside a session, tmux has a concept called "windows." A window is the tmux equivalent of a browser tab.
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

Conclusion: Panes split one window: Ctrl+b % goes left/right, the quoteWrapping a string in quote marks (' or ") so it is treated as one single value, e.g. one with spaces in it. key goes top/bottom.

Lina: Windows make sense! But "splitting the screen" is something different?
Linny-senpai: Right — that's panes. A pane is one section of a window, like a single piece of glass in a window frame. Panes divide one window into side-by-side regions.
Lina: So I could tail a log on the left and edit a file on the right?
Linny-senpai: Exactly. Seeing both at once saves you a lot of switching back and forth.

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

Conclusion: The big three pitfalls: holding the prefix, nesting tmux, and exit killing it.

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: You typed tmux, no new screen opened, and only this message appeared.

sessions should be nested with care, unset $TMUX to force

Cause: You are already inside tmux. By default, tmux refuses to nest itself.

Fix: Nothing is broken. Keep using the session you are already in. To confirm where you are, run echo $TMUX — any output means you are inside tmux.

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

Conclusion: SSH in, run tmux attach or tmux, detach with Ctrl+b d, return with tmux attach.

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

Conclusion: Practice detach/attach, window switching, and pane splitting to build memory.

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

Challenge 1: Open a Session, Detach, Reattach

Task: Open one tmux session. Step away from it, then come back.

Show Hint 1 (Direction)

Use the move that "steps away," not the one that closes. After stepping away, check whether the session is still listed.

Show Hint 2 (Command name)

Open with tmux. Step away with Ctrl+bd. List with tmux ls. Return with tmux attach.

Show Answer
$ 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

Task: Create a second window inside tmux. Move back and forth between the two.

Show Hint 1 (Direction)

A window is the tmux version of a browser tab. First do the "create" move, then try selecting a window by its number.

Show Hint 2 (Command name)

Create with Ctrl+bc. Select by number with Ctrl+b0 or Ctrl+b1. Cycle with Ctrl+bn.

Show Answer
$ 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

Task: Split the screen left and right. Then split it top and bottom, and run a different command in each pane.

Show Hint 1 (Direction)

Two symbols do the splitting. Match the shape of each key to the direction of the split. Movement uses the arrow keys.

Show Hint 2 (Command name)

Split left/right with Ctrl+b%. Split top/bottom with Ctrl+b". Move with Ctrl+b → arrow key.

Show Answer
$ 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.
Share this article

Next steps