October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Keep Processes Running After Closing an SSH Session (nohup, tmux, disown, and systemd-run)

An SSH logout can send SIGHUP to child processes and stop them. This guide shows how nohup, disown, tmux, screen, and systemd-run keep work running, when each method fits, and how to verify the result.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use tmux when you may need to reconnect and see the work; use nohup for a simple non-interactive command; use disown -h only when a job is already running; and use systemd-run when the process should be managed as a transient service. An SSH logout normally causes the shell to send SIGHUP (the hang-up signal) to child processes, so unprotected jobs often exit. The methods below prevent that signal from terminating the work or move the work into a persistent manager.

Why an SSH disconnect kills your process

SSH gives you a remote login shell attached to a terminal. When you log out, close the terminal, or lose the connection, that session ends. The shell then sends SIGHUP to processes associated with the session. Most ordinary child processes quit when they receive it, which is why a script can appear to work normally and then vanish as soon as your laptop sleeps or the network drops.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The solution is not to keep the SSH window open. Instead, start the command in a way that either ignores SIGHUP, removes it from the shell’s job management, runs it inside a persistent terminal multiplexer, or hands it to the service manager. These choices protect against an SSH logout, but they are not automatically a reboot strategy. Whether a job returns after a server reboot depends on a separate service configuration and is not established by these four commands.

Choose the method that matches the job

Method Survives SSH logout Reconnect and see the same terminal Managed by a service manager Does it background the command itself? Best use
nohup plus & Yes, when invoked correctly No No No; add & A one-shot, non-interactive script or command
disown -h Yes, when applied to the correct background job No No No; the job must already be stopped or backgrounded Protecting a command you forgot to prepare before logout
tmux (or screen) Yes Yes No The multiplexer keeps a session; you run the command inside it Interactive work, long builds, monitoring, and anything you may need to inspect
systemd-run Yes, as a detached transient unit No terminal reattachment Yes Service units start asynchronously by default; scope units wait Work that should have a named unit and service-manager lifecycle

If you are unsure, start with tmux. It gives you a way back into the running shell, so you can observe progress, answer prompts, or stop the command cleanly. Choose nohup when the command is fully unattended and you only need it to continue.

Run a simple command with nohup

What nohup changes

nohup starts another program with SIGHUP ignored. The signal disposition is changed immediately before the command is executed, so a later logout does not normally terminate that command because of the hang-up signal. POSIX specifies this signal handling at invocation.

nohup does not put the command in the background. Without an ampersand, your shell remains occupied until the command finishes, even though the command is protected from SIGHUP. The usual pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
nohup ./backup.sh > backup.log 2>&1 &

Here, the script is started with SIGHUP ignored, standard output is written to backup.log, standard error is merged into that same file, and the final & returns your prompt so you can log out.

Where output goes

If nohup sees that standard output is still a terminal, it redirects output to a file named nohup.out. It uses the current directory when possible, or $HOME/nohup.out as a fallback. Explicit redirection is safer because it gives the log a predictable name and prevents you from having to search for a file after disconnecting.

Use a separate log for each significant run rather than allowing unrelated commands to append to one shared file. For example:

nohup ./import-data.sh > import-2026-10-14.log 2>&1 &

Record the process identifier printed by your shell, or note the command name and log path. After reconnecting, inspect the log to determine whether the program completed; the fact that the SSH window closed successfully does not prove that the command finished successfully.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When nohup is the wrong tool

  • You need to interact with the program. A command that asks questions, displays a live dashboard, or requires occasional input is better inside tmux or screen.
  • You forgot to use it. You cannot retroactively wrap an already-running process with nohup; use the job-control procedure in the disown section if the shell still owns the job.
  • You expect full daemon behavior. nohup ignores SIGHUP, but it is not a complete daemonization framework. It does not provide a service unit, restart policy, or a reattachable terminal.
  • The command has its own shutdown logic. A program can exit for reasons unrelated to SIGHUP, such as an application error, a lost dependency, or an explicit timeout. Protecting the signal does not remove those failure modes.

Protect an already-running job with disown

How job control is involved

disown is a shell built-in that changes how the shell treats one of its jobs. The commonly reported form disown -h %1 keeps job 1 in the shell’s job table but prevents that job from receiving SIGHUP when the shell exits. This is useful when a command is already running and you did not start it with nohup.

The job must be stopped or running in the background before you can disown it. In an interactive shell, press Ctrl-Z to suspend the foreground command, resume it in the background with bg, and then apply disown -h to the correct job number.

  1. Press Ctrl-Z while the command is in the foreground.
  2. Run jobs and identify the job specification, such as %1.
  3. Resume that job: bg %1.
  4. Block the hang-up signal for it: disown -h %1.
  5. Confirm the shell has returned to a prompt, then disconnect.

Replace %1 with the number shown by jobs. Disowning the wrong job protects the wrong process, while leaving the intended job managed by the shell can still result in termination at logout.

Disown’s limitations

Shell job-control syntax and option details vary, so check the disown entry in the man page or built-in help on the target shell before relying on a flag in a production session. The procedure also depends on the original shell still being alive and still knowing about the job. If the SSH connection has already disappeared and the shell is gone, there is no remaining job table in which to run disown.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disown does not create a reattachable terminal and does not give you a service-manager unit. It is a rescue technique for a job you have already started, not a replacement for planning long-running work.

Use tmux for a persistent, reattachable session

Start and detach a tmux session

tmux separates a terminal session into a server and one or more clients. The server and its sessions continue on the remote host when your SSH client disconnects. You can later create a new SSH connection and attach to the same session.

  1. Start a named session: tmux new -s backup.
  2. Run your command inside that session, for example ./backup.sh.
  3. Detach without stopping the command by pressing Ctrl-B, then D.
  4. Close SSH. The tmux server remains on the remote machine.
  5. Reconnect and run tmux attach -t backup to see the existing terminal again.

Use a meaningful session name such as backup, build, or migration. Names make it easier to select the right work when several sessions are active. If you omit the target name while attaching, tmux can attach to an available session; specifying the name avoids ambiguity.

Why tmux is safer for interactive work

Unlike nohup and disown, tmux preserves the terminal context. Output remains visible when you reattach, and you can answer a prompt, inspect a live command, or interrupt it deliberately. A temporary network failure is treated as a detached client rather than as the end of the remote shell that owns the work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

tmux does not make a failing application reliable. If the command exits because of an error, the tmux window will still be there, but the process will not restart automatically. For restart and service lifecycle requirements, use a service manager instead.

screen as an alternative

screen provides the same broad model: start a persistent session, run the command inside it, detach, and later reattach. It is useful on systems where screen is already installed or is the local standard. The key property is persistence of the remote terminal session, not the particular multiplexer name.

Hand the command to systemd-run

Transient service units

systemd-run asks systemd to create a transient unit for a command. A service unit runs under the service manager, detached from your interactive shell, and starts asynchronously by default. Give it a stable name with --unit=:

systemd-run --unit=backup-job ./backup.sh

The unit name lets you distinguish this job from other transient work and gives administrators a clear object to inspect using the host’s normal systemd tooling. The process is no longer dependent on the lifetime of your SSH shell in the way an ordinary child process is.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Scope units

A scope unit is another mode of systemd-run. It runs the command as a child of systemd-run and waits for that command to finish. Use the scope form when the caller should remain attached until completion:

systemd-run --scope --unit=backup-job ./backup.sh

Because a scope waits, it is not interchangeable with the default service behavior when your immediate goal is to return to the prompt and disconnect. Choose deliberately: service units are detached and asynchronous by default; scopes keep the invoking command waiting for completion.

Set unit properties when needed

systemd-run accepts --property= options so you can assign supported unit properties at launch. The exact property names and permissions depend on the systemd version and host policy, so verify them in the target machine’s systemd-run(1) documentation before deploying a command. A property option changes how systemd manages the unit; it does not turn a terminal session into tmux or provide terminal reattachment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Step-by-step decision guide

Choose nohup for a fire-and-forget batch task

Select nohup when the program needs no interaction after launch, you are comfortable reading a log later, and you only need protection from the SSH logout signal. Use explicit output redirection and the trailing ampersand. This is the shortest command and has the fewest moving parts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose tmux when observation or input matters

Select tmux when you may need to watch progress, respond to a prompt, inspect a live console, or reconnect after an accidental disconnect. Start the named session before launching the work; do not wait until the network is unstable.

Choose disown only after the command is already running

Select disown -h when stopping and restarting the operation would be costly and the original shell still owns a background job. It is faster than rebuilding the command, but it offers neither logs by itself nor a way to reconnect to the terminal.

Choose systemd-run for service-style control

Select systemd-run when the process should appear as a named unit under systemd and be separated from the interactive shell. Decide whether the default asynchronous service unit or a waiting scope matches the workflow, and confirm that your account is allowed to create the requested unit.

Verify that the process really survived

  1. Launch with one method. Avoid testing several wrappers around the same command; otherwise you may not know which process is still running.
  2. Note the method-specific identifier. Save the log filename for nohup, the job number for disown, the session name for tmux, or the unit name for systemd-run.
  3. Disconnect deliberately. Log out or close the SSH client instead of merely opening another terminal.
  4. Reconnect as the same remote user. A tmux session, shell job, or unit may belong to a different account.
  5. Check the result. Reopen the tmux session, inspect the log, or query the process and unit with the host’s normal process and systemd tools. Confirm that the command is still making progress rather than merely leaving an empty shell behind.

Test with a harmless command before entrusting a long migration or backup to a new server. A short controlled run exposes shell differences, permission restrictions, logging mistakes, and missing utilities while recovery is easy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common failures

The process still exits immediately after logout

Check that the command was actually started through the protection method. With nohup, the ampersand belongs at the end of the complete command, and output redirection must be attached to that command. With disown, confirm the job number from jobs before applying disown -h. With tmux, make sure the command was launched inside the tmux session rather than in the original SSH shell.

You cannot find nohup.out

Look first in the working directory and then in $HOME/nohup.out. Better still, launch the command again with an explicit log path such as > backup.log 2>&1. The fallback filename is only used when standard output is a terminal; explicit redirection removes that uncertainty.

disown reports no such job

Run jobs in the same shell that started the command. A process launched by another SSH login, a different shell, or a shell that has already exited will not appear in your current job table. If the command is still recoverable, restart it inside tmux or launch it with nohup instead of guessing at a job number.

tmux attach finds no session

Use the same remote account that created the session and attach to the correct host. A session name is local to that machine and user context. If the command already exited, the session may remain but show a completed shell; if the tmux server itself was terminated, there is no session to attach to and the original process must be recovered by another method.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

systemd-run behaves differently than expected

Check whether you used the default service mode or --scope. A service starts asynchronously, while a scope waits for its child command. Also verify the requested unit name and properties against the installed systemd documentation and your account’s permissions. A successful launch only means systemd accepted the unit; inspect the unit and its output to determine the command’s actual result.

Important boundaries

These techniques address the SSH-session boundary and the SIGHUP signal. They do not guarantee survival of a machine reboot, kernel failure, power loss, resource exhaustion, or an application-level crash. They also do not automatically restart a failed process. If a workload must return after reboot or recover from failure, design a persistent system service separately rather than treating nohup, disown, tmux, or screen as a substitute.

For a single unattended command, the practical default is nohup command > log 2>&1 &. For anything you may need to inspect, use a named tmux session. If the job is already running, use Ctrl-Z, bg, and disown -h before closing SSH. When systemd should own the lifecycle, launch a named transient unit with systemd-run.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.