tmux auto-attach
tmux keeps your programs running on the server when the connection drops. ZestSSH can attach to tmux for you in two ways:
- A startup command: the host types
tmux new-session -A -s main(or anything else) each time you connect, and you work in tmux in the terminal as usual. - tmux control mode: Open tmux shows tmux’s windows as tabs and its panes as panes inside ZestSSH, with no prefix keys and no status line.
Both are free on every plan.
Attach with a startup command
Section titled “Attach with a startup command”-
Open the host’s editor. On a computer, go to Advanced. On a phone, tap Advanced options.
-
Under Automation, type the command in Startup command (optional). For example:
Terminal window tmux new-session -A -s main -
Save the host.
The startup command runs once, automatically, each time you connect to the host. It is typed into the shell and entered right after the host’s environment variables are exported, and before its Run snippet (optional). When ZestSSH reconnects a dropped session by itself, the command runs again, so a command like the one above takes you back into the same tmux session.
The startup command can be any command, not only tmux: cd /var/www && tmux attach, screen -dR main, or source ~/project/env.sh.
When you open a terminal from SFTP with Open terminal here, that terminal goes to the folder instead, and the startup command does not run.
tmux control mode
Section titled “tmux control mode”In control mode, tmux tells ZestSSH about its windows and panes, and ZestSSH draws them itself:
- each tmux window is a tab, with New window, Rename window and Close window,
- each pane is a pane, with Split pane right, Split pane down, Zoom pane and Close pane,
- Sessions lists the host’s tmux sessions and switches between them,
- Detach leaves; the session keeps running on the host.
Open tmux
Section titled “Open tmux”On a computer:
- In a session, open the command palette and choose Open tmux (control mode), or press Ctrl+Shift+X (on a Mac ⌃⇧X).
- On the Hosts page, choose Open tmux in a host’s menu.
- A host’s card shows how many tmux sessions it had the last time ZestSSH looked. Click that count to attach.
On a phone:
- In a session, open the terminal toolbar’s menu and choose Open tmux.
- On the Hosts tab, open a host’s actions and choose Open tmux.
Open tmux connects first if the host has no session open. Then it lists the host’s sessions under tmux sessions: tap Attach on one, or type a name and choose New session. If tmux is not on the host, ZestSSH says “tmux is not installed on this host” and shows how to install it.
Start control mode from the shell
Section titled “Start control mode from the shell”With Detect tmux control mode on (it is on at first), running tmux -CC in a terminal turns that tab into the tmux workspace. tmux -CC starts a new session and tmux -CC attach rejoins one. This also works on a host you reached through that terminal.
You find the setting under Settings > Terminal and SSH on a computer (in Behavior) and on a phone.
What asks for control mode is a short marker that any output can hold, a cat of a file or a line of a log, so ZestSSH does not take it at its word. It starts control mode by itself only just after a line that asked for it was entered: tmux -CC as you typed it (also tmux -uCC, or ssh web-01 -t "tmux -CC"), or what ZestSSH typed for you, as Open tmux or a startup command does. Otherwise a strip above the terminal asks: “Something printed in this session asks to start tmux control mode. ZestSSH would type tmux commands here, show a workspace this output draws, and send your keys to it. Do this only if you started tmux yourself. The output waits for your answer.” No is the plain answer, and going on typing is a no as well; Start tmux mode starts it.
A startup command can start control mode too, for example tmux -CC new-session -A -s main.
Install tmux on the server
Section titled “Install tmux on the server”If tmux is missing, install it with the host’s package manager:
- Debian / Ubuntu:
sudo apt install tmux - Fedora / RHEL:
sudo dnf install tmux - Alpine:
apk add tmux - macOS:
brew install tmux
Good to know
Section titled “Good to know”- The startup command syncs with the host to your other devices. When you restore a backup, ZestSSH first lists the hosts in it that run a command or a snippet when they connect, so you can check them.
- Automation runs (a
zestssh://link, a workflow step, a scheduled task) run one command without a terminal and do not run the startup command. - History suggestions do not show in tmux control mode.
- Snippets can pick a tmux session from a list read from the host with the
$[TMUX]placeholder, or a screen session with$[SCREEN]. See Snippets.