How to keep sessions running after disconnect with tmux
Updated 7/20/2026
If you close the SSH connection, processes started in the terminal stop. tmux solves this: sessions stay alive on the server and you can reconnect to them anytime.
1. Install
apt-get update -y
apt-get install -y tmux
2. Start a session
tmux new -s work
3. Detach (the session stays running)
Press Ctrl+b then d. You can close SSH; the process continues.
4. Reconnect
tmux attach -t work
tmux ls # list sessions
When it is useful
- Long migrations or backups that must not be interrupted.
- Builds or database imports that take hours.
- Watching a live process without having to keep SSH open.
tmux or systemd?
tmux is for temporary, interactive tasks. For permanent services that must start on their own, use a systemd service.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Dev environments
How to create a systemd service for your app
Make your app start automatically and restart itself if it stops, with a systemd service.
Updated 7/20/2026Dev environmentsHow to install PHP (multiple versions) and Composer
Install the PHP version your project needs, along with Composer for package management.
Updated 7/20/2026Dev environmentsHow to manage environment variables and secrets
Keep passwords and keys out of your code, in environment variables, safely and correctly.
Updated 7/20/2026