Skip to content

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.

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.

tmux is in every major distribution’s package manager.

Debian / Ubuntu:

Terminal window
sudo apt update && sudo apt install tmux

Fedora / RHEL / CentOS:

Terminal window
sudo dnf install tmux

Arch Linux:

Terminal window
sudo pacman -S tmux

macOS (for Mac servers):

Terminal window
brew install tmux

Alpine Linux:

Terminal window
apk add tmux

Check the install with tmux -V.

The most useful pattern is to have ZestSSH attach to a tmux session each time you connect to a server:

  1. Open the host’s editor. On a computer, go to the Advanced tab. On a phone, tap Advanced options.

  2. Under Automation, set Startup command (optional) to:

    Terminal window
    tmux new-session -A -s main
  3. Save the host.

This command:

  • Creates a tmux session named main if there is none.
  • Attaches to the main session 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.

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.

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

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.

Put this in ~/.tmux.conf on your server for a phone-friendly setup:

Terminal window
# Start window numbering at 1 (easier to reach on a phone keyboard)
set -g base-index 1
setw -g pane-base-index 1
# A bigger scrollback buffer
set -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 terminal
set -g default-terminal "xterm-256color"
# Automatic window names
setw -g automatic-rename on

With 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.

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.

“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:

Terminal window
set -g prefix C-a
unbind C-b
bind C-a send-prefix