When working on remote servers via SSH, one of the most frustrating things is losing your connection—and with it, the long-running process you just kicked off. Enter tmux, a powerful terminal multiplexer that allows you to run, disconnect, and resume terminal sessions at will. In this guide, you’ll learn how to install tmux and use it to keep your processes running, even after you log out of your SSH session.
tmux?tmux (Terminal MUltipleXer) lets you manage multiple terminal sessions from a single window. It’s particularly handy when you need to:
Run long scripts or processes
Detach and reattach to sessions
Work in multiple terminal windows without using screen or multiple SSH sessions
tmuxsudo apt update
sudo apt install tmux
sudo yum install tmuxor for newer versions using dnf:
sudo dnf install tmuxbrew install tmux
sudo pacman -S tmux
Once installed, check the version:
tmux -Vtmuxtmux
Or give your session a name (recommended):
tmux new -s mysession
This opens a new terminal session within tmux.
tmuxNow that you’re in a tmux session, run your command or script as usual:
python myscript.py
Even if this is a long-running process, you don’t need to worry about staying connected.
To safely detach from the session and return to your regular shell:
Press Ctrl + B, then release both keys.
Press D.
You’ll see a message like:
[detached (from session mysession)]
You can now safely close your SSH session. The process will continue running in the background.
Later, when you SSH back into the server, you can reattach to your session:
tmux attach -t mysession
If you forget the name of the session:
tmux ls
This will list all active tmux sessions.
When your task is done, you can kill the session:
tmux kill-session -t mysession
Or kill all sessions (be careful!):
tmux kill-serverSplit panes: Ctrl + B, then % for vertical or " for horizontal
Switch panes: Ctrl + B, then arrow keys
Create new window: Ctrl + B, then C
Navigate windows: Ctrl + B, then N (next) or P (previous)
Using tmux is an essential skill for anyone who works on remote servers. It helps you:
Keep processes running after SSH disconnect
Easily switch between terminal windows and tasks
Improve your workflow and system resilience
Once you get comfortable with tmux, you’ll wonder how you ever managed without it.
