
Summary
- Terminal multiplexers allow you to run multiple commands in different virtual terminals within one terminal.
- Multiplexers like tmux let you run commands over remote connections without losing progress due to network interruptions.
- Popular options include GNU Screen, tmux, and Byobu.
If you work on remote Linux sessions, you’ve probably felt the pain of your connection going down in the middle of a time-consuming operation. Or you may want to run more than one session over a single SSH connection. A terminal multiplexer may be what you’re looking for.
What Is a Terminal Multiplexer?
A terminal multiplexer is a utility that lets you “multiplex” a terminal, or use a terminal as if it were multiple terminals. It’s similar to multiple terminal windows or tabbed terminals, but within one terminal. On modern computers, it’s typically in a Linux terminal emulator, but the concept dates back to when the main way of using computers was through dedicated text terminals.
A terminal multiplexer lets you run commands in one virtual terminal while switching to another terminal to execute other commands.
Why Use a Terminal Multiplexer?
With modern machines being able to run multiple terminal windows or use tabbed terminals, and both at the same time, why would you bother with a terminal multiplexer?
If you’ve ever been logged into a remote machine, such as a web server or perhaps even your own home lab server, and suffered a network glitch, you can see the advantage of a terminal multiplexer. Over a regular SSH session, you’ll find that even after the network comes back up, SSH will ignore your keystrokes. You’ll have to terminate and restart your SSH connection. If you were in the middle of a complex operation, such as updating packages or installing software, you’d have to start from scratch. SSH was designed for wired connections.
Tools like Mosh can eliminate much of this problem, but terminal multiplexers shine over remote connections. You can start a session, and if the connection breaks, you can reconnect and come back to it, as if nothing happened. You can start a long process, detach it, go do something else, reattach, and pick up where you left off. You can keep a session going on a remote machine, and detach and reattach as long as you like. As long as the server hasn’t been rebooted and your session stays up, you can dip in and out of it as much as you like.
If you’ve ever been on IRC and wondered why some users never logged off, it’s not because they’re somehow not sleeping, going to work, school or other things. OK, maybe they aren’t going to work or class, but the main way they stay logged in is to run a terminal multiplexer on a shell server somewhere. This is known as “idling,” just staying logged into IRC without saying anything.

Related
You Can Use the Internet the Old-School Unixy Way With Shell Accounts
Relive the early ’90s text-based internet.
The other obvious reason is to have multiple terminal windows. Again, this is an ability that becomes useful over remote connections, as most people running Linux on the desktop will usually use a window system like X11 or Wayland that already lets them run multiple terminal windows. In a pinch, they can use virtual consoles to run full-screen command-line sessions.
Without a terminal multiplexer installed on the remote machine, the only ways to multitask over SSH are to use job control or open multiple connections. The former can be cumbersome, while the latter needs more resources. It makes more sense to use the same connection when you can. If you need to run a command and refer to the manual page, you can have the shell in one window and the manual page in another. Many terminal multiplexers will let you show multiple windows on the same screen. It’s similar to using a tiling window manager.
Terminal multiplexers are best if you do a lot of work over remote machines, such as a web server, a shell account, or a home lab server. If you primarily use a desktop machine, you’re better off using multiple terminal windows or tabbed terminals. If you want your terminal windows laid out neatly, consider using a tiling window manager.
What Are Some Popular Terminal Multiplexers?
There are several terminal multiplexers that you can use on your Linux system.
GNU Screen: This is one of the oldest terminal multiplexers, predating Linux. GNU Screen has been around since 1987. Even back in the ’80s, with the growth of workstations, a lot of people were still stuck on character-based terminals. Screen made life easier for many of these users with the ability to split the cramped screen into multiple terminal windows. It also introduced the idea of detaching and reattaching sessions.
This was a boon for people who dialed into remote systems over modems. While I never used shell accounts in their heyday, I do remember the days of dial-up networking, and it was annoying when my modem was on a shared line and somebody picked up the receiver.
GNU Screen was largely unchallenged until it got some competitors in the 21st century.
tmux: originally developed as part of the OpenBSD project, it seems to have stolen GNU Screen’s thunder as the premier terminal multiplexer, being ported to nearly every Unix-like system in existence.
Byobu: Byobu was originally a fork of GNU Screen created for Ubuntu. The name comes from a Japanese word for a folding decorative screen. True to the modern use of terminal multiplexers for remote systems, it was primarily designed for use on Ubuntu servers. Over time, Byobu switched to primarily enhancing tmux instead of GNU Screen.
How Do You Use a Terminal Multiplexer?
Before you use a terminal multiplexer, you have to install it. I’ll demonstrate using tmux, as it happens to be my terminal multiplexer of choice.

Related
How to Use tmux on Linux (and Why It’s Better Than Screen)
Is the Linux tmux command really better than screen? We gave it shot to find out.
tmux is widely available for most major Linux distribution package managers. I’ll use Debian/Ubuntu as an example:
sudo apt install tmux
Now that I have tmux installed, I can launch it from the command line:
tmux
In tmux, I have another shell session going. I can enter commands into it just as if I were in a regular shell session. I can issue commands to tmux with the Ctrl+b prefix. To create another terminal window, I use Ctrl+b, then press c. This will open up another terminal window in tmux and switch to it. The current windows are listed on the bottom left corner of the terminal window on the status bar. To switch between windows, I can press Ctrl+b again, followed by the number of the window I want to move to.
I can also split a current window in to have more terminal sessions. To split the window horizontally, I can press Ctrl+b followed by a ” (double quote), and to split it vertically, I’ll press Ctrl+b followed by a % (percent) key. The sessions in each window are known as “panes” in tmux. I can switch between panes with the Ctrl+b followed by an o, and swap the pane positions with Ctrl+b followed by an O (upper-case O).
To detach a session, I can press Ctrl+b followed by a d. To reattach after I’ve detached it, I’ll type this at the prompt
tmux attach
I can copy and paste between sessions by going into the “copy mode,” but a lot of the time I’ll use the native copy and paste functions in my window system.
Terminal multiplexers might be obscure, but if you make extensive use of remote Linux machines, they can be useful in splitting one terminal session into multiple terminals and staying connected to your server even if your connection peters out. Picking a terminal multiplexer like tmux can make your online sessions more useful and even more fun.
Source link