Dec 23, 2025
Ariffud M. & Aris S.
9min Read
A terminal multiplexer, or tmux, is a command-line tool that lets you manage multiple terminal sessions in a single window. With tmux, you can split panes, create multiple windows, and keep sessions active in the background.
The primary benefit of tmux is persistence. If your SSH connection drops or you accidentally close your terminal emulator, the processes running inside tmux continue on the server. You can reconnect and resume work exactly where you left off.
The essential steps to mastering tmux include:
To use tmux, first install the utility on your server, then start a session using the tmux command.
Once inside a session, you use a specific prefix key (Ctrl + B by default) combined with other keys to perform actions such as splitting the screen or creating new windows.
When you finish working but want to keep processes running, you detach from the session. tmux keeps it active in the background until you attach to it again later.
Most Linux distributions do not include tmux by default, so you usually need to install it manually. You need superuser or root privileges to install packages.

sudo apt update # Debian and Ubuntu
sudo dnf makecache # RHEL, CentOS, and Fedora
sudo apt install tmux # Debian and Ubuntu
sudo yum install tmux # RHEL and CentOS
sudo dnf install tmux # Fedora
tmux -V
If the terminal returns a version number, such as tmux 3.4 or later, the installation succeeded. If you see a “command not found” error, verify your PATH or try reinstalling tmux.


You can start a tmux session by typing tmux in your main terminal window. By default, tmux assigns each session a numeric ID starting at 0.
This approach works for quick tasks but becomes hard to manage when you run multiple sessions at the same time.
We recommend starting each session with a custom name. When you run tmux ls to list sessions, numeric IDs such as 0, 1, or 2 provide little context. Descriptive names like backend-deployment or server-logs make each session’s purpose clear at a glance.
To start a named session, use the -s flag followed by your chosen name:
tmux new -s session-name
After you run this command, tmux clears the terminal and displays a status bar at the bottom of the screen. By default, the bar appears green, but you can customize it.

The status bar confirms that you are inside a tmux session. It shows the current shell (usually bash or zsh), the session name, and the current time.
One of tmux’s most important features is the ability to detach from a session. Detaching sends the session to the background and keeps all running programs active, while returning you to the main shell prompt.
This feature helps when you run long processes, such as database migrations, and need to disconnect your SSH client, or when your internet connection is unstable.
If the connection drops unexpectedly, tmux detaches the session instead of terminating it.
To detach from a session, press the prefix key Ctrl + B, release both keys, then immediately press D. The terminal will display a [detached] message.

To resume work, reattach to the session. If only one session is running, use:
tmux attach
If multiple sessions are active, specify the target session with the -t flag:
tmux attach -t session-name
You can also use a numeric session ID if you did not name the session, for example, tmux attach -t 0. But descriptive names are easier to remember than numbers.
Effective session management prevents your server from filling up with unused background processes or “zombie” sessions. Check active sessions regularly to stay organized.
To list all active tmux sessions, run the following command in your main terminal:
tmux ls
The output includes the following details:

If you are currently inside a tmux session, you can switch to another one using the following command. As with reattaching, specify the session name or ID:
tmux switch -t session-name
When you finish a task and no longer need the background processes, kill the session to free system resources.
To terminate the current session, type exit or press Ctrl + D. To kill a specific session without attaching to it, use the kill-session command:
tmux kill-session -t session-name
Warning! Use kill-session with caution. This command immediately stops all processes running in the session. If you have unsaved data in a text editor or an active database operation, you will lose it permanently.
A single tmux session can contain multiple windows, similar to tabs in a web browser or a GUI terminal application. This setup lets you keep different contexts separate within the same project without starting a new session.
For example, a typical workflow might include:
To create a new window, press Ctrl + B → C. The new window appears in the status bar at the bottom of the screen, marked with a new number and an asterisk (*) to indicate that it is active.

To navigate between windows:
By default, tmux names each new window after the active process, usually bash, sh, or zsh.
In a complex session with several windows, names like “bash” make it hard to tell which window contains logs and which one holds your editor.
Rename windows to reflect their purpose and make navigation easier:

The updated name appears immediately in the status bar, making window navigation faster.
Windows work well for separating distinct tasks, while panes let you divide a single window into multiple visible sections. This setup is ideal for multitasking when you need to cross-reference information.
For example, you might view real-time server error logs on the left side of the screen while triggering those errors by running commands on the right.
Use the following keybindings to split the current pane:
You can combine these commands to build complex layouts. For example, split the window left and right first, then split the right pane into top and bottom sections.
This creates one large pane on the left and two smaller panes on the right.

Important! tmux terminology can be counterintuitive. The % key creates a vertical divider, resulting in side-by-side panes. Meanwhile, “ creates a horizontal divider, resulting in stacked panes.
Once you split a window, typed commands affect only the currently active pane, which has a colored border. You need to move the focus to interact with other panes.
To switch between panes, press Ctrl + B, then use the arrow keys (Up, Down, Left, Right) to move in that direction. Alternatively, press Ctrl + B → O to cycle through panes sequentially.
Also, in some cases, the default 50/50 split is not efficient. You might prefer a large coding pane and a smaller terminal output pane.
To resize panes, press Ctrl + B, then use Ctrl + arrow keys, such as Ctrl + Up or Ctrl + Down, to resize in steps of one cell. Use Meta + arrow keys, like Alt + Up, to resize in steps of five cells.

When you finish working in a pane, you can close it without affecting the rest of the window or session. There are three ways to do this, ranging from safe to forceful.

| Shortcut | Action | Description | Use case |
| Ctrl + B → D | Detach session | Disconnects you from the session while keeping it running. | Log off SSH while a script continues to run. |
| Ctrl + B → C | Create window | Opens a new shell in a separate tab. | Separate a new task, such as database management, from your current task. |
| Ctrl + B → Shift + 5 (%) | Split left and right | Divides the screen into left and right panes. | Read code on one side and logs on the other. |
| Ctrl + B → Shift + ‘ (“) | Split top and bottom | Divides the screen into top and bottom panes. | Keep a monitoring tool, like top, visible below your work. |
| Ctrl + B → X | Kill pane | Closes the active pane after confirmation. | Remove a split pane you no longer need. |
| Ctrl + B → , | Rename window | Changes the window name shown in the status bar. | Organize complex sessions with many windows. |
| Ctrl + B → Z | Zoom pane | Toggles the active pane between full screen and normal view. | Temporarily focus on a specific log file without closing other panes. |
| Ctrl + B → [ | Copy mode | Enters copy mode to scroll through terminal history. Press Q to exit. | Review previous output or copy text. |
| Ctrl + B → W | List windows | Shows an interactive list of all windows in the session. | Navigate sessions when you have too many windows to remember by number. |
| Ctrl + B → Shift + / (?) | List key bindings | Displays a help screen with all configured keybindings. | Quickly look up a shortcut you have forgotten. |
To customize tmux, create or edit the .tmux.conf configuration file, then add your custom settings. After saving the file, apply the changes by running tmux source-file ~/.tmux.conf inside a tmux session.
The configuration file can be local (applying only to your user) or global (applying to all users on the server). We recommend using a local configuration file to avoid disrupting other users.
The local configuration file is named .tmux.conf and resides in your home directory. Starting with version 3.2, tmux also checks $XDG_CONFIG_HOME/tmux/tmux.conf (typically ~/.config/tmux/tmux.conf).
Create or edit the file using the nano text editor:
nano ~/.tmux.conf
You can add commands to change tmux behavior. Below are two common and recommended tmux customizations.
# Unbind the default prefix unbind C-b # Set the new prefix to Ctrl + A set -g prefix C-a bind C-a send-prefix

set -g mouse on
After making your changes, save the file and exit nano by pressing Ctrl + X → Y → Enter.
Saving the file does not apply changes to the running tmux server. tmux reads .tmux.conf only when the server starts, not when you create new sessions.
To apply the new configuration immediately without restarting the server, run the following command inside a tmux session:
tmux source-file ~/.tmux.conf
Best practices for using tmux include creating a structured workspace, keeping sessions persistent and secure, and avoiding configuration bloat.
By treating tmux as a workspace manager rather than just a window splitter, you can significantly improve your command-line efficiency.
Effective use of tmux starts with understanding its hierarchy: session → window → pane.
Avoid running everything in a single window with many split panes. This makes the terminal hard to read and navigate. If a window becomes too cluttered, move a pane to its own window by pressing Ctrl + B → ! (exclamation point).
The most important function of tmux is session recovery. In a standard SSH session, if your Wi-Fi drops or your computer goes to sleep, the SSH connection breaks and sends a SIGHUP signal that terminates running commands.
tmux prevents this behavior. If your SSH connection times out:
Your cursor returns to the exact position where you left off, with command history and running processes intact.
Common tmux mistakes often come from treating it like a simple terminal tool rather than a session manager. Below are the most frequent issues and how to avoid them.
After learning how to use tmux, the next step in your terminal workflow is to integrate it with secure remote management practices to build a more robust server environment.
To get more value from remote sessions, check our guide on essential SSH commands.
It covers core tasks such as navigating directories, managing files, and editing configuration files, all of which you will perform regularly inside tmux sessions.
All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.
Comments
December 29 2021
This is probably the best short explanation of tux with one exception. You forgot to list one of the most powerful and useful commands.... CTRL B : setw synchronize-panes This allows you to type the command once and have it executed in every open pane. I.E. if you are installing Kubernetes on multiple nodes you can open an ssh session to separate nodes in each pane. Then typing the command "sudo yum install -y kubelet kubeadm kubectl" execute on the server in each pane simultaneously. (this assumes you have the kube repo setup) To stop the sync just type the command again... CTRL B : setw synchronize-panes
December 30 2021
Awesome, thanks Joe! I'll check with the team to include this in the article as well :)