Return to Archive
Mission Briefing
Tmux Sessions: Keep Programs Running After You Close the Terminal
November 2025
#Linux#Tmux#How-To
SME Classified
Install tmux, detach from a running program, and come back to it later, even after closing your SSH session.
Lab Walkthrough
01
Install tmux
I used Ubuntu (Debian based) to install this.
Terminal Input / Command
sudo apt update
sudo apt install tmux -y02
Start a single tmux session
If you only need one session: start tmux and run your program. Detach with Ctrl + b, release both keys, then press d. You can now exit and log out. After connecting to the system again, attach to the session you detached from.
Terminal Input / Command
tmux
python3 oneway.py
# Ctrl + b, release both keys, then d (detach)
exit
ssh root@ip # connect to the system again
tmux attach # attach to the most recently detached session03
Check tmux sessions and connect
List the existing sessions. Sessions without names are numbered 0, 1, 2 and so on. Attach to the most recent session, or to a specific one (session 2 here).
Terminal Input / Command
tmux ls
tmux attach # most recently detached session
tmux attach -t 2 # session 204
Create and run multiple tmux sessions
Named sessions keep programs organized and easy to find. Create a session called MyFirstSession, run your program, detach, and attach again by name. Create as many named sessions as you need.
Terminal Input / Command
tmux new -s MyFirstSession
python3 oneway.py
# Ctrl + b, release both keys, then d (detach)
tmux attach -t MyFirstSession