Tutorial

Keep a process running after SSH disconnect (tmux, nohup)

Closing SSH kills your running command via SIGHUP. Run it in tmux or screen to keep it alive and reattach later, or use nohup for fire-and-forget. Why this matters double on mobile, where connections drop.

CC Chen Chen· Founder·June 14, 2026·5 min read

Keep a process running after you disconnect

By default, closing an SSH session kills whatever you started in it. To keep a command running after you disconnect, start it in a terminal multiplexer — tmux (or screen) — which the best, most flexible option. For a quick one-off, nohup … & works too. On mobile this matters double: connections drop when you switch networks or the app is backgrounded, so detaching is the difference between losing a job and not.

Why it dies

When your SSH session ends, the shell sends SIGHUP ("hang up") to its child processes, and most quit. The fix is to run the process somewhere that survives the session — a detached tmux/screen session, or a process explicitly told to ignore the hangup.

The best way: tmux

tmux keeps a shell alive on the server independently of your connection. Start it, run your work, detach, disconnect — the work keeps going. Later you reattach exactly where you left off.

tmux                      # start a session
# … run your long command …
# detach: press Ctrl-b then d
# now you can disconnect safely

# later, after reconnecting:
tmux attach               # back exactly where you were

If you have several sessions: tmux ls lists them, tmux attach -t 0 picks one. screen is the older equivalent (screen, detach with Ctrl-a d, reattach screen -r) — use whichever is installed.

The quick way: nohup

For a single command you just want to launch and leave:

nohup ./long_job.sh > job.log 2>&1 &

nohup makes the process ignore the hangup, & backgrounds it, and the redirect captures output to a file (since there's no terminal to print to). Check progress later with tail -f job.log. Already started a command and forgot? disown -h %1 detaches the most recent background job from the shell so it survives.

Which should you use?

Want to…Use
Come back and interact with the sessiontmux / screen
Fire-and-forget one command, read logs laternohup … &
Save a job you already starteddisown

Why this is essential on mobile

On a phone, the connection is fragile by nature: you walk out of Wi-Fi range, switch to cellular, or the OS suspends the app during a long wait — and a plain SSH session (and its running command) dies, often with a broken pipe. Running inside tmux makes the drop a non-event: the job keeps running on the server, and you reattach with tmux attach when you reconnect. Pair it with a stable address (Tailscale) and reconnecting is a single tap. It's the habit that makes phone admin reliable.

TermAI suggesting a tmux command on a phone
On mobile, starting long work inside tmux means a dropped connection doesn't kill the job — reattach when you reconnect. The AI can set it up if you're unsure of the commands.

FAQ

How do I keep a process running after closing SSH?
Start it inside tmux (or screen), detach with Ctrl-b then d, and disconnect — the process keeps running. Reattach later with tmux attach. For a one-off, use nohup command &.

What's the difference between tmux and nohup?
tmux keeps an interactive session alive that you can reattach to; nohup just launches one command that ignores the hangup and runs in the background. Use tmux when you want to come back to the session.

I already started a command — can I save it?
Yes: disown -h %1 detaches a running background job so it survives the session. (It must already be backgrounded with Ctrl-z then bg, or started with &.)

Why do my jobs die when SSH drops on mobile?
The dropped session sends SIGHUP to its processes. Run them in tmux so they're independent of the connection — essential on mobile where drops are common.

Quick Facts

  • Why jobs die: closing SSH sends SIGHUP to its child processes
  • Best: run in tmux — detach (Ctrl-b d), disconnect, tmux attach later
  • Quick: nohup command > log 2>&1 & for fire-and-forget
  • Already running: disown -h %1 to save it
  • Mobile: tmux turns a dropped connection into a non-event
Try TermAI

Free on iOS and Android. 5 AI requests/day on the free tier, plus unlimited SSH/SFTP and built-in Tailscale.

CC
Chen Chen — Founder of TermAI

Writes about mobile DevOps, terminal UX, and the surprising depth of "boring" infrastructure.

Was this useful? ← Back to blog