Skip to main content
Browse referenceKeep Work Running over SSH

Keep Work Running over SSH

Reconnect to the same remote shell and its running work after your SSH connection drops.

Verified Sep 2026 for tmux 3.7c
6 min read
beginner

Outcome: leave a harmless timer running on a remote host, disconnect, and return to that same timer. You need SSH access and tmux installed on the remote host. The default prefix is Ctrl+b; release it before pressing the following key.

Start tmux on the remote host

Connect from your local terminal, substituting your normal SSH destination:

bash
ssh your-user@your-host

Once logged in, run these commands in the remote shell:

bash
hostname
tmux -V
tmux new-session -A -s remote-work

The status bar marks your tmux session. -A attaches to remote-work if it already exists; otherwise it creates it. Check what is already running before typing into an existing session. The official getting-started guide explains this create-or-attach behavior.

Start your work inside this remote tmux session. Starting tmux on your laptop and then SSHing from its pane does not move the remote shell into a remote tmux server.

Verify with a harmless timer

At an idle shell prompt inside the remote session, run:

bash
while :; do date; sleep 5; done

A timestamp appears every five seconds. This loop writes only to the terminal and continues until you stop it with Ctrl+c in its pane.

Press Ctrl+b, release both keys, then press d. You return to the remote shell outside tmux. Run:

bash
tmux list-sessions

You should see remote-work listed. If nobody else is attached, its entry will not say (attached). Now run exit in that outer SSH shell to disconnect. The tmux server and timer stay on the remote host.

Detaching removes your view of the session. Typing exit inside its pane ends that pane's shell; closing the last pane ends the session. These are different operations. Session persistence and the default detach binding are specified in the tmux 3.7c manual.

Reattach after a disconnect

Reconnect to the same host and user account, then inspect and attach:

bash
ssh your-user@your-host
tmux list-sessions
tmux attach-session -t '=remote-work'

The = requests an exact session-name match. You should see timestamps from while you were disconnected and new ones arriving. Press Ctrl+c to stop the practice timer. Your shell and session remain open; you can now start your actual work there.

Use attach-session for this check because it reports a missing session instead of silently creating a replacement. Attaching without -d leaves other clients connected. If you deliberately want to disconnect an old client, inspect tmux list-clients first; attach-session -d -t '=remote-work' detaches the other clients of that session.

What survives and what does not

An SSH disconnect normally leaves the remote tmux server and its programs running. tmux does not preserve running processes across a host reboot, server termination, or a process crash. Host logout policies may also terminate user processes. Save files normally and use your application's checkpointing or a service manager when the job needs recovery beyond a disconnected terminal.

A running program may have its own network connection that fails independently of tmux. Returning to its pane does not guarantee that the program's work succeeded; inspect its output or status.

If your session is missing

  • Wrong destination: check hostname and whoami; a load-balanced SSH alias can land on a different machine.
  • Different tmux server: custom -L socket names or -S socket paths must match the original launch. Avoid switching user accounts with sudo when looking for your session.
  • Session ended on detach: inspect tmux show-options -s exit-unattached before your next attempt. An enabled value tells the server to exit when its last client leaves. Also check remote logout policies.
  • Already inside tmux: use Ctrl+b s to choose an existing session on that server, or detach first. Do not unset TMUX just to suppress the nesting warning.

Practice and continue

Practice session management or use the playground to rehearse the prefix and detach keys. These simulate tmux behavior in your browser; the timer check above verifies a real SSH session. Use the tools hub to prepare or check your configuration.

Next: copy text from the remote session or organize editor, tests, and logs.