tmux Basics for Beginners

tmux Basics for Beginners

Anyone who has lost a long-running command because an SSH connection dropped has felt the exact problem tmux exists to solve. tmux (terminal multiplexer) lets you run a terminal session that keeps going independently of whether you are currently connected to it, and lets you split a single terminal into multiple panes and switch between multiple named sessions. Once it clicks, it is hard to go back to working without it, especially for anything involving remote servers.

Installing tmux

sudo apt install tmux      # Debian/Ubuntu
sudo dnf install tmux      # Fedora/RHEL
sudo pacman -S tmux        # Arch
sudo zypper install tmux   # openSUSE

Starting a session

tmux

This opens a new tmux session, taking over your current terminal. You will see a status bar at the bottom listing the session and window information. To start a session with a specific name, useful when you plan to run several:

tmux new -s work

The prefix key

Nearly every tmux command starts with a prefix key combination, by default Ctrl+b, followed by a second key for the specific action. So “split the pane” is Ctrl+b then %, not one single keypress. The prefix exists so tmux’s own shortcuts do not collide with keybindings used by whatever is running inside the terminal, be it a shell, a text editor, or anything else. Throughout this guide, “prefix” means pressing Ctrl+b, releasing it, then pressing the next key.

Detaching and reattaching

This is the core workflow that makes tmux valuable. Start something long-running inside a tmux session, detach from it, and it keeps running in the background whether or not you stay connected:

# Inside a tmux session, detach with:
# prefix, then d

tmux ls
# work: 1 windows (created Thu Aug  8 10:02:00 2026)

tmux attach -t work

tmux ls lists all currently running sessions. tmux attach -t work reattaches to the session named work, exactly as it was left, including anything that was running inside it. If your SSH connection drops unexpectedly rather than being deliberately detached, the tmux session survives regardless, since it runs as a separate process on the server, independent of your SSH connection. Reconnect and tmux attach picks up right where you left off.

Windows

A tmux session can contain multiple windows, similar to tabs in a browser:

prefix, c       create a new window
prefix, n       next window
prefix, p       previous window
prefix, 0-9     jump directly to window number 0 through 9
prefix, w       show a list of all windows to choose from
prefix, ,       rename the current window

Windows are useful for keeping separate, unrelated tasks organized within one session, such as one window for editing code and another for running a build or watching logs.

Panes

Within a single window, panes split the terminal into multiple visible sections:

prefix, %       split vertically (side by side)
prefix, "       split horizontally (stacked)
prefix, arrow   move between panes in the direction of the arrow
prefix, z       zoom the current pane to fill the window temporarily (press again to un-zoom)
prefix, x       close the current pane (or just type exit inside it)

Panes are especially useful for keeping related output visible at the same time, such as tailing a log file in one pane while running commands in another, without switching back and forth between separate windows.

A realistic workflow

A common real use case: starting a long-running task on a remote server over SSH, then disconnecting without losing it.

ssh user@server
tmux new -s deploy
./long-running-deploy-script.sh
# prefix, d    (detach, script keeps running)
exit           # close the SSH connection entirely, the script is unaffected

Later, from the same machine or a different one:

ssh user@server
tmux attach -t deploy

The script’s output, and its running state, is exactly as it was, because it was never actually connected to your SSH session in the first place, only to the tmux session running independently on the server.

Customizing tmux

tmux reads ~/.tmux.conf on startup for configuration. A common first customization is remapping the prefix key, since Ctrl+b is a stretch for some keyboard layouts and hand positions:

# ~/.tmux.conf
set -g prefix C-a
unbind C-b
bind C-a send-prefix

After editing, apply the change to an already-running session without restarting it:

tmux source-file ~/.tmux.conf

tmux vs screen

screen solves largely the same problem and predates tmux, and is still present by default on more systems out of the box. tmux is generally considered more modern: more consistent scripting and configuration, more flexible pane management, and more active ongoing development, which is why it is the more common recommendation for anyone learning a terminal multiplexer today. Knowing basic screen commands is still worth having as a fallback for systems where tmux is not installed and cannot easily be added.

Frequently Asked Questions

What problem does tmux actually solve?

tmux solves two related problems. First, it lets a terminal session keep running even if your connection drops or you intentionally disconnect, which matters enormously over SSH: without tmux (or a similar tool like screen), closing an SSH connection kills every process running in that session, including long-running commands you meant to leave running. Second, it lets you split one terminal window into multiple panes and switch between multiple independent sessions, without needing to open several separate terminal windows or SSH connections.

What is the difference between tmux and screen?

Both solve the same core problem, terminal sessions that persist independently of your connection, and both use a similar detach/reattach model. tmux is generally considered more modern, with a more consistent scripting interface, more flexible pane splitting and resizing, and more active development, which is why it has become the more commonly recommended default for new users. screen is older and still present by default on more systems out of the box, so it remains useful to know as a fallback on a system where tmux is not installed and you cannot install it. For anyone learning one from scratch today, tmux is the more common recommendation.

How do I reattach to a tmux session after disconnecting?

Run tmux attach, or tmux attach -t sessionname if you have multiple named sessions and want a specific one. If you are not sure what sessions exist, tmux ls lists every active session with its name, number of windows, and creation time. This is the core of tmux’s value: start a long-running task inside tmux, detach (deliberately or via a dropped connection), reconnect later from the same machine or a different one, and the session, along with everything running inside it, is exactly as you left it.

What is the prefix key in tmux and why does everything start with it?

tmux commands are triggered by pressing a prefix key combination first, by default Ctrl+b, followed by a second key that specifies the actual action. For example, detaching from a session is Ctrl+b then d, and splitting a pane vertically is Ctrl+b then %. The prefix exists so that tmux’s own keybindings do not collide with keybindings used by whatever program is running inside the terminal (a text editor, a shell, or anything else), since without a distinct prefix there would be no reliable way to tell “this keypress is for tmux” apart from “this keypress is for the program I am running.”

How do I create multiple panes in a single tmux window?

Press Ctrl+b then % to split the current pane vertically (side by side), or Ctrl+b then ” to split it horizontally (stacked). Switch between panes with Ctrl+b then an arrow key, and close a pane by typing exit or pressing Ctrl+d inside it, the same way you would close a normal shell. Panes are useful for keeping related things visible simultaneously, such as a log file tailing in one pane while you run commands in another, without needing separate terminal windows.

Can I customize tmux keybindings and appearance?

Yes, tmux reads a configuration file at ~/.tmux.conf on startup, where you can remap the prefix key, change default pane split behavior, adjust the status bar, and set many other options. A very common first customization is remapping the prefix from Ctrl+b to Ctrl+a, since Ctrl+a is easier to reach for many people and was the default in screen, which many long-time users are already used to. Changes to ~/.tmux.conf take effect on the next new tmux session, or immediately in an existing session after running tmux source-file ~/.tmux.conf.