When you are managing a Linux server remotely via SSH, you are tied to the active terminal session. If you start a massive database migration, a system backup, or a complex software compilation, that process is firmly tethered to your SSH connection. If your local Wi-Fi drops, your laptop battery dies, or you simply close the terminal window, the SSH connection breaks, and Linux will instantly kill your running process.
To safely detach your critical processes from your fragile SSH connection, Linux administrators use a terminal multiplexer called tmux.
What is tmux?
tmux (Terminal Multiplexer) acts as a virtual container for terminal sessions. When you start tmux, it creates a persistent shell session running in the background of the server. You can run your long-winded commands inside this container, and then deliberately “detach” from it. The container (and your command) continues running perfectly on the server, even after you completely disconnect and turn off your local computer.
Installing tmux
Most modern Linux distributions include tmux in their official repositories. To install it, use your package manager.
On Ubuntu/Debian systems:
sudo apt update
sudo apt install tmux
On RedHat/CentOS systems:
sudo yum install tmux
Starting a New tmux Session
Before you run a command that you know will take a long time, you must launch the tmux container first.
- In your SSH terminal, simply type:
tmux - Press Enter.
Your screen will refresh, and you will notice a green status bar at the very bottom of the terminal window. You are now “inside” the persistent tmux session.
You can now type your long-running command (for example, wget for a massive file, or a Python script) and execute it.
Detaching from the Session
Once your command is running, you want to leave the container without killing the process. This is called “detaching.”
tmux uses a specific “prefix” key combination to accept commands. By default, the prefix is Ctrl+B.
- Press and hold Ctrl, then tap B.
- Release both keys.
- Tap the D key (for Detach).
You will instantly drop back out to your standard SSH shell, and the green status bar will vanish. A message will confirm you have detached. Your process is now safely running in the background. You can safely close your terminal window or shut down your computer.
Reattaching to the Session
Hours or days later, you can log back into your server via SSH to check on your process.
To see a list of active tmux sessions running in the background, type:
tmux ls
To jump back “inside” the container and see your command’s progress, type:
tmux attach
The screen will instantly refresh, bringing back the green status bar and showing you exactly where your command left off. If the command has finished, you can close the tmux container permanently by typing exit and pressing Enter.