FDE Times dataFDE jobs open 928▲21 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 85Companies hiring 200Remote-friendly 24%Median US pay $200kTop hirer Databricks 107
中文VI

The newspaper of the Forward Deployed Engineer

Tools

Your SSH link to the client's server drops. Is the job still running?

Typing one tmux command before you start a long job means you can reattach to the old session after a dropped connection, so nothing has to run again.

ShareLinkedInFacebookX

In brief

  • The tmux manual says sessions are persistent and survive accidental disconnection, such as an SSH timeout.
  • Type tmux new-session -A -s <name> every time you SSH in: it creates the session if it does not exist and attaches to it if it does.
  • tmux does not transfer files, and a session ends once no program is running in it, so it is no substitute for rsync or a proper service.
GraphicA job that survives an SSH drop
  1. 1SSH into the client's machineBefore running anything, open or reattach a session with a fixed name.
  2. 2tmux new-session -A -s migrateCreates the session if it does not exist, attaches if it does.
  3. 3Run the job in the sessionThe program runs under the tmux server, independent of the SSH window.
  4. 4The network dropsOnly the client is lost; the server and the job keep running on the machine.
  5. 5SSH back in, attach the right sessionattach-session -d -t migrate clears the stale client and reattaches the named session.

State lives in the tmux server on the remote machine, so losing the SSH client does not lose the job.

Graphic: FDE Times

The official tmux manual puts it plainly: sessions are persistent and survive accidental disconnection, such as when an SSH connection times out. For an FDE running commands on a client’s server over a flaky VPN or meeting-room Wi-Fi, that one line matters more than any other feature in the tool.

The risk is that a long job started directly in an SSH window is tied to that connection. A data migration halfway through, or a three-hour backfill, can die just as you are presenting to the client.

The tmux Getting Started guide recommends exactly this: to protect programs running on a remote server from connection drops, run them inside tmux. The advice is simple, but using it properly means understanding how tmux keeps a session alive.

Why does the session survive when you lose the connection?

The tmux wiki defines it as a terminal multiplexer. It lets you switch between several programs in one terminal and detach from them while they keep running in the background. You can then reattach from a different terminal.

The key is how tmux organizes its processes. It keeps all of its state in a single main process, the tmux server, which runs in the background on the server machine itself. Your SSH window is only a client looking at that server, so a network drop loses the client while the server and the programs inside it carry on.

The server starts automatically with the first tmux command you type, so there is nothing to launch by hand; the only thing to check in advance is whether tmux is installed on the client’s machine. By default the server also exits when no programs are left running, and that is the first limit to remember.

One command for every login

Take a team that needs to run a script moving customer data to a new schema on the client’s own server. Straight after SSHing in, before doing anything else, type:

tmux new-session -A -s migrate

The -A flag is what makes the command repeatable. According to the manual, if a session named migrate already exists, new-session -A behaves like attach-session, attaching you to the existing session instead of creating a new one. The first time you get a fresh session; every time after that, the same command takes you back to where you left off.

Inside the session, run the script as usual. Say the client’s VPN cuts out midway. You SSH back into the machine, type the same line, and the script is still running with its output intact on screen.

One irritating case comes up often: the old connection has not been fully closed, so the session still thinks a client is attached. In that case, use attach-session with the -d flag and name the session explicitly:

tmux attach-session -d -t migrate

The manual states that -d detaches any other clients attached to the session, so the ghost client is removed and you regain full control.

The session name matters because attach-session with no target picks the most recently used session that nobody is attached to. The migrate session still appears to have a client, so tmux may drop you into a different session.

Where tmux will not save you

The biggest limit comes from the very fact that all state lives in one server process. A session lives only while something is running inside it: if the script exits with an error and the shell closes too, the server can shut down and take the error output with it.

For the same reason, if the machine itself reboots, the session is gone. Run jobs from an interactive shell inside the session, and write logs to a file.

The tmux FAQ also states that tmux is not a file transfer program. It preserves your terminal but does nothing to push a large dump file across an unreliable link. That needs a different tool.

The last point is security, which matters on a client’s shared servers. The FAQ explains that tmux relies on file system permissions to limit who can access its socket.

It follows that if a team shares one system account, anyone who logs into that account can attach to your session and see what you are doing, including variables holding credentials.

Turn the habit into a runbook

Do not start with key bindings or config files. Learn exactly three things: new-session -A -s, attach-session -d -t, and the server/client model behind them. From there, fold the limits above into a short runbook template for any long job on client infrastructure:

# 1. Log in with your own account, not a shared one
ssh <your-own-account>@<client-host>

# 2. Name the session after the ticket
tmux new-session -A -s <ticket>

# 3. Run the job from an interactive shell, logging to a file so there is evidence if the session is lost
./job.sh 2>&1 | tee ~/logs/<ticket>.log

# 4. After a network drop: clear the stale client and attach to the right session
tmux attach-session -d -t <ticket>

Step 1 deals with the socket on shared machines, step 2 tells you and your colleagues which session belongs to which piece of work, and step 3 covers the chance that the session disappears along with the server.

When an FDE interviewer asks how you would run a risky migration on a client’s machine, walking through these four steps and the reason for each is far more convincing than “knows tmux” on a CV.

Break it once on purpose

On a staging machine, open a session with tmux new-session -A -s drill and run a loop that stands in for a backfill, such as for i in $(seq 1 600); do echo $i; sleep 1; done | tee ~/drill.log. When the counter reaches a few dozen, turn off Wi-Fi on your laptop and wait until the SSH window reports the connection lost.

Turn Wi-Fi back on, SSH in and type tmux attach-session -d -t drill. If the counter is still climbing and the log file has no gap, you have first-hand proof that the job survived the drop.

Run this drill once on staging, and on the day the client’s VPN cuts out in the middle of a real migration, all you need to do is retype the same command.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
4 sources
Read next on the roadmap · Stage 1: FoundationsBefore you ask the client's engineers, ask the call sitesSourcegraph shows where code starts, what calls it and who changed it lately, so the first question you take to the client is already narrow.