tmux: Keep a Command Running After You Close SSH
A command that you start over SSH stops when the SSH window closes or your connection drops. For long tasks, such as unpacking a large archive, copying many files or a long download, start the command inside tmux. tmux keeps it running on the service; later you connect again and see how far it got. The steps were tested with tmux 3.2 on our demo service.
First connect to your service: SSH how to get connected.
1. Start a Named Session
tmux new -s copy
The window looks almost the same as before, with a green bar at the bottom. It shows the name of the session, here [copy], and the command that is running. Start your long command here as usual, for example an unpack or a copy.
2. Leave the Session Running
Press Ctrl+B, release both keys, then press D. tmux shows [detached (from session copy)] and you are back in the normal SSH window. The command keeps running. You can now close the SSH window.
3. Come Back Later
Connect over SSH again and list your sessions:
tmux ls
It shows, for example, copy: 1 windows (created Sat Nov 28 00:39:45 2026). Return to the session:
tmux attach -t copy
You see the window as you left it, with all the output of the command.
4. Useful Keys
All tmux keys start with Ctrl+B; release it, then press the next key:
- D: leave the session running (detach);
- [: scroll back through the output with the arrow keys or Page Up; Q ends scrolling;
- C: open a second window in the same session; N switches to the next one.
5. End a Session
When the command has finished, type exit inside the session. tmux shows [exited], and the session disappears from tmux ls. To end a session from outside, together with the command running in it: tmux kill-session -t copy.
screen Works Too
If you know screen, it is installed as well. screen -S copy starts a session, Ctrl+A then D leaves it, screen -ls lists the sessions and screen -r copy returns to one.
screen -ls also lists sessions that you did not start, for example rtorrent or syncthing. Your apps run in them. Do not open or end these sessions: pressing Ctrl+C there stops the app. To restart an app, use the buttons in the Client Area.
Your service is shared with other users. Use tmux for tasks that come to an end, such as unpacking, copying or downloading.
Examples of long tasks: Unpack RAR, ZIP and 7z Archives on Your Service via SSH and Download Files From a Link Straight to Your Service.