What happens when your SSH connection drops while running a long process on a server? In a classic session, the running process ends too. tmux and screen are "terminal multiplexer" tools that solve exactly this problem. This guide explains how to set up persistent terminal sessions.
Related reading: Connecting to a server with SSH · systemd service management
What Is a Terminal Multiplexer?
tmux and screen are tools that let you manage multiple sessions, windows and panes within one terminal. Their most important feature is this: you can "detach" the session on the server, keep it running even if your connection drops, and "attach" to it again later.
This way you can start a backup, build or update that takes hours, then close the connection; later you return and check the process's status. tmux is more modern and feature-rich, while screen is older and available ready on almost every system.
Why Is tmux Necessary?
- The job does not die if the connection drops: Processes inside tmux continue even if the SSH session closes.
- Multiple windows in one terminal: You can watch logs in one window while running commands in another.
- Resume work where you left off: You can return in the evening to the session you started in the morning, in the same state.
- Screen sharing: Multiple people can connect to the same session and work together.
Basic tmux Usage
In tmux, all commands start with a prefix key; the default is Ctrl+b. You press this key first, then the command key.
# Start a new named session
tmux new -s backup
# Detach from the session (the process keeps running): Ctrl+b then d
# List running sessions
tmux ls
# Reattach to the session
tmux attach -t backup
| Shortcut (Ctrl+b then) | Function |
|---|---|
d | Detach from the session |
c | Open a new window |
n / p | Next / previous window |
% | Split pane vertically |
" | Split pane horizontally |
arrow keys | Switch between panes |
Basic Usage with screen
screen is a simpler alternative. You start a new session with screen -S name, detach with Ctrl+a then d, and reattach with screen -r name. The logic is the same as tmux; only the prefix key is Ctrl+a.
tmux or a systemd Service?
tmux is ideal for manual and temporary long processes. But if an application needs to run continuously (permanently), the right tool is not tmux but a systemd service — it comes back up automatically when the server reboots. Use tmux for interactive jobs, systemd for permanent services.
Frequently Asked Questions
Should I choose tmux or screen?
If you are starting out, tmux is recommended: it is more actively developed and more powerful for pane management and customization. screen comes installed on almost every system and is enough for simple needs.
Do tmux sessions survive a server reboot?
No. tmux and screen sessions only protect against SSH drops; when the server reboots, sessions are lost. Use a systemd service for jobs that must run permanently.
Can I scroll back through output inside tmux?
Yes. Press Ctrl+b then [ to enter scroll mode, and look back with arrow keys or PageUp/PageDown. Press q to exit.
Run your long processes with confidence on KEYDAL VPS; with stable infrastructure your connection stays solid. Explore KEYDAL hosting