--- title: tmux โ€” session-preserving terminal date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A terminal multiplexer that keeps your session alive even if the connection drops during remote work. Essential for deployments and long-running tasks. tags: program, Remote server connection management, tmux --- **๐Ÿ’ฌ "tmux commands"** tmux **maintains sessions** on the server. Even if ssh disconnects, tasks keep running. It is the standard tool for safely running long deployments, batch jobs, and log following. - **Concept**: creates virtual terminals to manage sessions, windows, and panes. - **Session**: create with new and reattach with attach. - **Split**: " vertical split, % horizontal split, move with arrow keys. - **Prefix key**: defaults to Ctrl+b, then combine it with another key. ## Commonly used options | Option | Description | | --- | --- | | new -s | Create a named session | | attach -t | Reattach to an existing session | | ls | View the session list | | -d attach | Detach other clients and attach | ## Three essential command combinations - `tmux new -s deploy` โ€” create a session for deployment - `tmux ls` โ€” check the current session list - `tmux attach -t deploy` โ€” reattach to the deployment session after disconnection **๐Ÿ’ฌ "Show me an example for comparing before and after performance tests"** Here are common situations you encounter on production servers, organized in order. ### Step 1 ยท Create a session Create a named session before starting work. ``` tmux new -s deploy ``` ### Step 2 ยท Run the task Start a long-running task inside the session. ``` cd /opt/app && ./bin/deploy.sh 2>&1 | tee /tmp/deploy.log ``` ### Step 3 ยท Detach and reattach Detach with Ctrl+b d, then reattach to check progress. ``` tmux attach -t deploy ``` ## In practice, it's used like this ### 1. Long-running deployment **Situation** โ€” If ssh disconnects during a 20-minute deployment, the task dies. ``` tmux new -s deploy 'bash -lc "./bin/deploy.sh 2>&1 | tee /tmp/deploy.log"' ``` **Result** โ€” Deployment runs inside the session and continues even if the connection drops. **Point** โ€” After reattaching, check progress by tailing the log file. ### 2. Long-term batch monitoring **Situation** โ€” You want to watch an overnight batch job in real time. ``` tmux new -s batch 'tail -F /var/log/app/batch.log' ``` **Result** โ€” You can attach at any time to view logs, and collection continues even after you leave. **Point** โ€” Giving each session a task-specific name makes it easy to distinguish multiple jobs. ## Things to keep in mind - If you pass a command as an argument and it finishes, the tmux session also exits (keep a log file for review). - Sessions disappear on server reboot. For permanent execution, set it up as a systemd service. - If you don't know the prefix key (Ctrl+b), it can look like key input isn't working. ## Actual execution screen This is the result of checking the tmux session list and reattaching to the deployment session. ![tmux command execution result: session list and deployment progress](https://games.aidebatehub.com/assets/tmux-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/remote/tmux.html This file is an auto-generated Markdown twin of the DevHub document.