tmux workflow with ZestSSH
Mobile SSH connections drop. Wi-Fi hands off, cellular towers switch, phones put background apps to sleep. When a plain SSH session dies, any program running in it dies with it. tmux solves this by keeping your session alive on the server, ready to reattach when you reconnect.
Why tmux matters for mobile
Section titled “Why tmux matters for mobile”ZestSSH sends keep-alive packets to cut down on idle disconnects, but network interruptions are unavoidable on mobile. tmux (or screen) runs on the server, so:
- A dropped connection does not kill your running programs.
- You can reconnect from another device and pick up where you left off.
- You can start a long build or deployment, lock your phone, and check the results later.
Installing tmux on your server
Section titled “Installing tmux on your server”tmux is in every major distribution’s package manager.
Debian / Ubuntu:
sudo apt update && sudo apt install tmuxFedora / RHEL / CentOS:
sudo dnf install tmuxArch Linux:
sudo pacman -S tmuxmacOS (for Mac servers):
brew install tmuxAlpine Linux:
apk add tmuxCheck the install with tmux -V.
Attach every time you connect
Section titled “Attach every time you connect”The most useful pattern is to have ZestSSH attach to a tmux session each time you connect to a server:
-
Open the host’s editor. On a computer, go to the Advanced tab. On a phone, tap Advanced options.
-
Under Automation, set Startup command (optional) to:
Terminal window tmux new-session -A -s main -
Save the host.
This command:
- Creates a tmux session named
mainif there is none. - Attaches to the
mainsession if it is already running.
Each time you connect, you land in your tmux session. If the connection dropped while a build was running, you reconnect and see its output waiting for you. The startup command is typed into the session once it is up, for SSH, Mosh and Eternal Terminal hosts alike.
Named sessions per purpose
Section titled “Named sessions per purpose”For servers where you do different kinds of work, use a different session name per host. Add two hosts for the same server:
- “prod logs” with the startup command
tmux new-session -A -s logs - “prod deploy” with the startup command
tmux new-session -A -s deploy
Each host drops you into its own tmux session.
tmux control mode: tmux windows as ZestSSH tabs
Section titled “tmux control mode: tmux windows as ZestSSH tabs”ZestSSH can also show tmux itself: in tmux control mode, tmux’s windows become tabs and its panes become panes inside ZestSSH, with no prefix keys to learn. Start it with Open tmux from a host’s menu (right-click on a computer; on a phone, long-press the host, then More and Host actions). When tmux -CC starts in a terminal, ZestSSH switches to this view by itself while Detect tmux control mode is on (it is on unless you turn it off). See tmux auto-attach for the details.
Essential tmux commands
Section titled “Essential tmux commands”All tmux commands start with the prefix key, which is Ctrl+B by default. Press Ctrl+B, release, then press the command key.
| Action | Keys |
|---|---|
| New window | Ctrl+B then c |
| Next window | Ctrl+B then n |
| Previous window | Ctrl+B then p |
| Split pane left and right | Ctrl+B then % |
| Split pane top and bottom | Ctrl+B then " |
| Switch pane | Ctrl+B then an arrow key |
| Detach (leave the session running) | Ctrl+B then d |
| List sessions | tmux ls |
| Attach to a session | tmux attach -t main |
| End a session | tmux kill-session -t main |
| Scroll mode (copy mode) | Ctrl+B then [ |
| Leave scroll mode | q |
| Rename window | Ctrl+B then , |
| Resize pane | Ctrl+B then Ctrl + an arrow key |
ZestSSH’s touch gestures
Section titled “ZestSSH’s touch gestures”On a phone or tablet, ZestSSH’s terminal gestures work well with tmux:
- Two-finger tap sends
Ctrl+C, handy for stopping a command inside a tmux pane. - Three-finger tap pastes from the clipboard, for pasting commands into tmux.
- Two-finger swipe left or right switches between your ZestSSH sessions, useful when you have several servers open beside your tmux windows.
- Pinch changes the font size.
Recommended tmux configuration
Section titled “Recommended tmux configuration”Put this in ~/.tmux.conf on your server for a phone-friendly setup:
# Start window numbering at 1 (easier to reach on a phone keyboard)set -g base-index 1setw -g pane-base-index 1
# A bigger scrollback bufferset -g history-limit 50000
# Mouse support (taps and scrolling from the terminal)set -g mouse on
# A short escape delay (responsive on slow connections)set -sg escape-time 10
# 256-color terminalset -g default-terminal "xterm-256color"
# Automatic window namessetw -g automatic-rename onWith mouse on, you can tap a tmux pane to switch to it and scroll its buffer by swiping. On a computer the mouse is then tmux’s: hold Shift while you drag to select and copy to your own clipboard, and hold Shift while you right-click to paste (4.1.1). ZestSSH tells the server its terminal is xterm-256color.
tmux, Mosh and Eternal Terminal
Section titled “tmux, Mosh and Eternal Terminal”On computers (Windows through WSL, macOS and Linux), ZestSSH can also connect with Mosh and Eternal Terminal. Both keep a connection going when your network changes, without a session manager on the server.
They solve a different problem from tmux, and the two work well together:
- Mosh and Eternal Terminal keep the connection alive across network changes.
- tmux keeps the session alive when the connection really ends (the device is off, the app was closed, the Mosh server was restarted).
For the most resilience on a computer, connect with Mosh or Eternal Terminal and attach to tmux with the startup command. You get both a connection and a session that survive.
On phones and tablets (Android, iPhone and iPad), Mosh and Eternal Terminal are not available, so tmux is your main defense against disconnects. Keep-alive is on by default: the app-wide Keepalive interval is 30 seconds (on a phone in Settings > Terminal and SSH; on a computer, SSH keepalive interval in Settings > Terminal and SSH), and a host can set its own Keepalive interval in its editor (on a computer, the Network tab), with Use global default as its default. Let tmux take care of recovery when a drop happens anyway.
Troubleshooting
Section titled “Troubleshooting”“sessions should be nested” warning: this happens when you start tmux inside a tmux session. The tmux new-session -A -s main startup command avoids it by attaching instead of nesting.
Garbled display after reconnecting: press Ctrl+B, then :, and type refresh-client. You can also change the terminal’s size (rotate your device, or pinch to change the font size) to force a redraw.
Prefix key clashes: if Ctrl+B clashes with your shell or editor, change it in ~/.tmux.conf:
set -g prefix C-aunbind C-bbind C-a send-prefix