You SSH into a machine, kick off a long job, background it, redirect its output to a file, and close the laptop with the comfortable feeling that it will keep running. You come back an hour later and it’s gone: the log stops dead a few seconds after you disconnected, the work half-finished, no error anywhere. You did everything the old advice says, nohup included, and the job still died the moment you hung up.
SIGHUP, sent to the session’s processes when the terminal goes away; nohup, disown, or setsid make the job ignore or escape it, and it survives. On Windows OpenSSH an SSH disconnect kills background processes outright and nohup does not help: the SSH server puts every process your session starts into one Windows job object and terminates that entire job object when the session ends, so your whole background tree – nohup and all – is destroyed within seconds of disconnecting. A job object is killed by command, not by a signal, so a tool whose only trick is to ignore SIGHUP has nothing to ignore. The fix on Windows is to start the work outside the SSH session entirely: launch it as a scheduled task (or a real service) so it runs under the scheduler’s process tree instead of your session’s, and the disconnect leaves it untouched.The reason this is so disorienting is that the exact same instinct – “background it and nohup it” – is correct on one operating system and useless on the other, and nothing in the command you typed tells you which world you’re in.
Table of Contents
The job that dies when you hang up
The setup is ordinary. You open an SSH session to a server, start something that will take a while – a build, a data import, a batch of downloads – send it to the background, point its output at a logfile, and go. The whole point of backgrounding and redirecting is that the job no longer needs your terminal, so losing the connection should be harmless.
Often it isn’t. The job stops at almost the same instant your SSH client exits. The logfile is the tell: its last line lands a few seconds after the disconnect and then nothing, mid-task, with no error message – because nothing failed, something terminated the process from outside, and a terminated process doesn’t get to write a complaint on its way out.
What’s happening is that the job you backgrounded was still a child of your SSH session, and when the session ends, the machinery that cleans up the session reaches your job too. Backgrounding (&) detaches the job from your shell’s foreground; it does not detach it from the session. That distinction is the whole story.
Backgrounding a job detaches it from your shell’s foreground, not from the SSH session that owns it.
On Unix, nohup really does work
On a Unix-like server, the mechanism is a signal. When your controlling terminal disappears – which is what a dropped SSH connection looks like – the kernel sends SIGHUP (“hang up”, a name inherited from the days of modems and physical terminal lines) to the processes attached to it. The default action for SIGHUP is to terminate, so a naive long-job & dies.
The classic fixes all target that one signal:
nohupruns the job withSIGHUPset to be ignored, and (when output is a terminal) redirects its streams to a file, so the job neither receives the fatal signal nor needs the terminal it just lost.disowntells your shell to drop the job from its table so the shell won’t forward a hangup to it.setsidruns the job in a brand-new session with no controlling terminal at all, so there’s no terminal whose loss could signal it.- A terminal multiplexer such as
screenortmuxkeeps a session alive on the server independent of your connection; you reattach to it later.
On Unix these genuinely work, because they address the actual cause. Ignore or sidestep SIGHUP and the job keeps running after you disconnect. This is the advice everyone remembers, and on a Linux box it is correct.
On Windows, an SSH disconnect kills background processes outright
Carry the same habit to a Windows server running the OpenSSH service and it quietly fails. Background a job, nohup it in Git Bash, redirect its output, disconnect – and come back to find it dead, the log cut off seconds after the session closed. In a direct test, a nohup‘d two-minute sleep, started over SSH and left running, was already gone about ten seconds after the SSH client returned to its own prompt. nohup made no difference at all.
The cause isn’t a signal. Microsoft’s port of OpenSSH for Windows manages each connection’s processes with a Windows job object – a kernel construct that groups processes so they can be controlled, and terminated, as a unit. Every process your session spawns, and every process those spawn, lands in that one job object. When the session ends, the server tears the job object down, and a job object configured to kill on close takes its entire membership with it, all at once. Your backgrounded tree is inside that membership, so it goes too.
On Windows OpenSSH, your session’s processes share one job object, and closing the session terminates the whole object.
Why nohup can’t help here
Once you see the mechanism, the reason nohup is powerless becomes obvious. nohup‘s entire job is to make a process ignore SIGHUP. But a job-object termination is not SIGHUP – it is not any signal. It’s the kernel being told “end every process in this object,” and there is no flag a member process can set to opt out. Ignoring a signal that is never sent accomplishes nothing.
The same reasoning sinks the other Unix escapes. disown and setsid are about forwarded hangups and controlling terminals – signal machinery – not about leaving a Windows job object, and there is no tmux to reattach to. The job object is assigned when your connection is accepted, before your shell even starts, so nothing you run inside the session can climb out of it.
That’s the trap: the tools look like they should work – they’re the right tools for the symptom “process dies on disconnect” – but they’re built for a different cause than the one actually killing your job.
You connect, start a long job, background it and redirect its output – even with nohup. It runs fine while you're connected.
Windows OpenSSH put the session's processes in one job object; the disconnect terminates it whole – nohup and all – in seconds.
Launch the work via Task Scheduler or a service: it runs under the scheduler's tree, not your session's, so disconnecting leaves it running.
nohup only ignores SIGHUP; the Windows kill is a job-object termination, not a signal. Start the job outside the session.
The fix: start the job outside the session
If a process can’t escape the job object from inside the session, the answer is not to start it inside the session. Hand the work to something whose process tree is independent of your SSH connection, and ask that thing to run it.
On Windows, the straightforward tool is the Task Scheduler. Instead of running long-job directly over SSH, you register a one-off task and start it:
schtasks /create /tn MyJob /tr "C:\tools\long-job.cmd" /sc once /st 00:00 /ru SYSTEM /f
schtasks /run /tn MyJobCode language: JavaScript (javascript)
The task runs under the Task Scheduler service, not under your sshd session, so its process tree is outside your session’s job object. You can now disconnect freely; the job keeps running, and you poll it or read its log on your next connection. A long-lived background worker is better registered as a proper Windows service (or wrapped by a service manager), which is the same idea made permanent: the service control manager owns the process, not your login.
Two neighbouring gotchas bite people the moment they move a job out to a scheduler, and both have their own walkthroughs:
- The scheduled task may suddenly report command not found even though the script runs perfectly by hand, because a scheduled task gets a different, nearly empty
PATH. That’s the subject of why your scheduled task’s PATH is nearly empty – call tools by absolute path inside the task. - If you give the task a “run only when the user is logged on” trigger, you’ve just rebuilt a dependency on your session by another route, and it will stop after a reboot nobody signs into. See why an always-on service secretly waits for you to log in – use “run whether the user is logged on or not.”
On a Unix host you also have systemd-run --user or a service unit, which likewise detaches long work from your login session. The principle is identical on both systems: ownership, not backgrounding, is what survives a disconnect. A job lives exactly as long as whatever owns its process tree, so to outlive your SSH session it must be owned by something that isn’t that session.
This is the mirror image of a related surprise, where you kill a worker and the job keeps going anyway because its parent script marches on – why killing a process doesn’t stop the job it belongs to. Both come down to one question: which process owns the work? On a Windows workstation, the two-SSH-agents trap is another place the platform’s SSH behavior diverges from the Unix mental model.
The short version
A job you background over SSH is still a child of the SSH session, so when the connection drops the session’s cleanup can take the job with it. On Unix the trigger is the SIGHUP signal, and nohup, disown, setsid, or tmux make the job survive by ignoring or escaping it – the familiar advice, and it works. On Windows OpenSSH the trigger is different: the server puts your session’s processes in a single job object and terminates the whole object on disconnect, which is not a signal and cannot be ignored, so nohup makes no difference and a backgrounded job dies within seconds. The fix is to run the work outside the session – register it as a scheduled task or a service so it lives under the scheduler’s process tree, not your login’s. The rule underneath both systems: a job survives a disconnect only if something other than your SSH session owns it.
Frequently Asked Questions
Does nohup work over SSH on Linux?
Yes. On a Linux or other Unix-like server, a dropped SSH connection causes SIGHUP to be sent to the session’s processes, and the default response to SIGHUP is to terminate. nohup runs your job with that signal ignored (and redirects its streams off the terminal), so the hangup never kills it and the job keeps running after you disconnect. disown, setsid, and a tmux/screen session achieve the same end by other means. The reason the same approach fails on Windows OpenSSH isn’t that nohup is broken – it’s that Windows doesn’t kill the job with SIGHUP in the first place, so there’s nothing for nohup to suppress.
Why does my background process die after I disconnect on Windows but not Linux?
Because the two systems end the session differently. Linux signals the processes (SIGHUP), which a process can be told to ignore. Windows OpenSSH groups every process your session spawns into one job object and terminates that whole object when the session closes – a wholesale kill issued by the kernel, with no per- process opt-out. So a Unix escape that only has to dodge a signal has no equivalent to dodge on Windows, and the backgrounded tree is taken down with the session. Move the job to the Task Scheduler or a service and its process tree is no longer part of your session’s job object, so it survives.
Will screen or tmux keep my job alive on Windows?
Not in the usual way – and often not at all, because tmux and screen aren’t native to Windows. Even where you have a POSIX-style multiplexer under an environment like Git Bash or WSL, it doesn’t change the fact that the Windows OpenSSH server placed your connection in a job object that dies with the session. The dependable Windows answer is to not keep the job in the session at all: register it with the Task Scheduler, or run it as a service, so something outside your login owns it. On Linux, by contrast, tmux/screen work exactly as advertised.
Is running it as a Windows service better than a scheduled task?
For anything long-lived or recurring, yes. A scheduled task is the quickest way to launch a one-off job outside your SSH session, but a Windows service is built for work that should run continuously, start at boot, and be managed (start, stop, restart, recovery) by the service control manager rather than by a login. Both share the key property that fixes this problem – their process tree is independent of your SSH session – so either survives a disconnect; the service just adds lifecycle management a one-shot task doesn’t have. If you reach for a scheduled task, watch the task’s PATH and its logon trigger, the two neighbouring traps linked above.