If you use SSH to work on a remote Linux server, tmux is one of the first tools worth learning.
The problem it solves is simple: if your SSH connection drops, anything running in that terminal usually stops with it. That is a bad fit for long-running work like Codex, editors, logs, build processes, servers, or monitoring tools.
tmux gives you a persistent terminal session on the remote machine. You can disconnect from SSH, come back later, and continue exactly where you left off.
The concepts articulated in this blog post originated from me and were composed with an AI assistant. I have performed edits for clarity and coherence. This post has the category
AI Slopassociated with it to be transparent on the authorship of this content for those who don’t want to waste their time reading mostly AI generated content.
This guide uses a practical scenario:
- You SSH into another Linux server
- You run Codex there
- You may also have other programs open, like logs, shells, editors, or build commands
- You want all of that to keep running even if you disconnect
What tmux actually is
Think of tmux as a terminal workspace manager that lives on the remote server.
Your local computer connects to the server with SSH. Inside that SSH connection, tmux creates a session that keeps running on the server even after your network connection goes away.
That means:
- SSH disconnects do not kill your
tmuxsession - Programs started inside
tmuxkeep running - You can reconnect later and reattach to the same session
It does not survive a server reboot. If the remote machine restarts, the tmux session is gone.
The basic workflow
A typical daily flow looks like this:
- SSH into the server
- Start or attach to a
tmuxsession - Run Codex and any other commands inside that session
- Detach from
tmuxwhen you want to leave - Disconnect from SSH
- SSH back in later and reattach
Step 1: SSH into the server
From your local machine:
ssh your-user@your-server
Now you are in a shell on the remote machine.
Step 2: Start a tmux session
Create a new named session:
tmux new -s work
The name work can be anything. Use names that describe the purpose, such as codex, deploy, or project-a.
Once you run that command, you are inside a tmux session.
Step 3: Run your tools inside tmux
Now start Codex or anything else you want to keep alive.
For example:
codex
Or maybe you also want another shell for logs or a server process. Inside tmux, you can create more windows and panes for that.
A practical layout might be:
- one window for Codex
- one window for application logs
- one window for a shell
- one pane for a dev server
The key point is that all of these should run inside tmux if you want them to survive an SSH disconnect.
Step 4: Detach without stopping anything
When you want to leave, do not close the terminal first.
Detach from tmux with:
Ctrl-b, thend
That means:
- hold
Ctrland pressb - release both keys
- press
d
After detaching, you go back to the normal shell on the remote server, but the tmux session and everything inside it are still running.
Now you can safely exit SSH:
exit
Step 5: Reconnect later
SSH back into the same server:
ssh your-user@your-server
List tmux sessions:
tmux ls
Reattach to your session:
tmux attach -t work
You are back where you left off.
The single most useful command
In practice, you often want to attach if the session already exists, or create it if it does not.
Use this:
tmux attach -t work || tmux new -s work
This is a good default command after SSHing into the server.
Sessions, windows, and panes
This is the part that confuses most beginners.
Session
A session is the top-level workspace.
For your scenario, a session might represent:
- one remote server
- one project
- one major task
Example session names:
codexapiprod-fix
Window
A window is like a tab inside a session.
Use windows when the work belongs together.
Example inside one codex session:
- window 1: Codex
- window 2: logs
- window 3: shell
- window 4: tests
Pane
A pane is a split terminal inside one window.
Use panes when you want to see multiple terminals at once.
Example:
- left pane: Codex
- right pane: logs
When to use multiple sessions vs multiple windows
Use multiple windows when the tasks are related.
Use multiple sessions when the contexts should stay separate.
A good rule:
- same project or same server task: new window
- different project or risky different environment: new session
Example:
- session
staging- windows for Codex, logs, shell
- session
production- windows for monitoring and maintenance
This separation reduces mistakes. If you are working on production, you want that to be clearly separate from staging or development.
Essential tmux shortcuts
All default tmux shortcuts begin with the prefix:
Ctrl-b
Press Ctrl-b, release, then press the next key.
Session commands
tmux new -s work
tmux ls
tmux attach -t work
tmux kill-session -t work
Detach
Ctrl-b d— detach and leave everything running
Windows
Ctrl-b c— create a new windowCtrl-b n— next windowCtrl-b p— previous windowCtrl-b w— choose a window from a listCtrl-b ,— rename the current window
Panes
Ctrl-b %— split left/rightCtrl-b "— split top/bottomCtrl-bplus arrow keys — move between panesCtrl-b z— zoom the current paneCtrl-b !— break the current pane into its own window
Scrolling in tmux
A common beginner problem is that normal terminal scrollback stops working the way you expect once you are inside tmux.
Use tmux copy mode instead:
Ctrl-b [— enter scroll mode- use arrow keys,
PgUp, orPgDn q— leave scroll mode
If you want mouse scrolling to work better, enable mouse support in your config.
A simple tmux config for beginners
Create ~/.tmux.conf on the remote server with:
set -g mouse on
set -g history-limit 100000
set -g status off
What these do:
mouse onenables mouse scrolling and pane selectionhistory-limit 100000gives you much more scrollbackstatus offhides the bottom status bar if you find it distracting
Reload the config from inside tmux with:
tmux source-file ~/.tmux.conf
Should tmux commands be run inside or outside tmux?
Usually either is fine.
Examples like these are commonly run from inside tmux:
tmux set-option status off
tmux source-file ~/.tmux.conf
That is normal.
A practical Codex-over-SSH workflow
Here is a simple workflow that maps directly to your use case.
SSH into the remote server:
ssh your-user@your-server
Attach or create your session:
tmux attach -t codex || tmux new -s codex
Inside tmux:
- run Codex in one window
- create another window for logs with
Ctrl-b c - create another window for a shell or tests
When you need to leave:
- detach with
Ctrl-b d - then run
exit
Later, reconnect and reattach:
ssh your-user@your-server
tmux attach -t codex
Everything is still there as long as the server has not rebooted.
Common mistakes beginners make
Running the important command outside tmux
If you start Codex before entering tmux, it is tied to that SSH session. If SSH drops, that process may stop.
Start tmux first, then run the important command inside it.
Forgetting to detach
If you just close the terminal abruptly, tmux often still survives, but you should get in the habit of detaching cleanly with Ctrl-b d.
Creating too many sessions too early
Beginners often create many sessions when a few windows would be easier to manage.
Start simple:
- one session per project or server task
- several windows inside that session
Not naming sessions
Named sessions are easier to reattach to than anonymous ones.
Prefer:
tmux new -s codex
instead of just:
tmux
Minimal cheat sheet
New session: tmux new -s work
List sessions: tmux ls
Attach: tmux attach -t work
Attach or create: tmux attach -t work || tmux new -s work
Detach: Ctrl-b d
New window: Ctrl-b c
Split vertical: Ctrl-b %
Split horizontal: Ctrl-b "
Move panes: Ctrl-b + arrow keys
Scroll mode: Ctrl-b [
Exit scroll mode: q
Final rule
If you want a process to survive your SSH disconnect, make sure it starts inside tmux.
That is the core habit. Once that is clear, the rest is just learning a few shortcuts.