nohup on Linux: Run Commands in the Background After SSH Logout

nohup linux - custom-nohup-featured.png

nohup on Linux is searched constantly — you start a backup or data import over SSH, close the laptop, and wonder if the process died. nohup (no hang up) tells the shell to ignore the hangup signal so the child keeps running when your session ends.

Alternatives: tmux,
cron,
systemd services.

What nohup Does

When SSH disconnects, the kernel sends SIGHUP to your shell — by default that kills background jobs unless they are immune.

SIGHUP
hangup

Basic nohup Syntax

Append & to run in the background; capture the PID for later checks.

bashlong job
nohup ./long-backup.sh >> /var/log/backup.log 2>&1 &
echo $! > /var/run/backup.pid
nohup &
PID

Redirect stdout and stderr

Default nohup.out in the current directory is messy — always point logs somewhere explicit.

bashredirect
nohup myjob.sh > /var/log/myjob.log 2>&1 &
2>&1″ /><figcaption>log file</figcaption></figure>
<h2>disown for Existing Jobs</h2>
<p>Already started a job? <code>disown -h</code> removes it from the shell job table so SIGHUP does not reach it.</p>
<div class=
bashdetach
./slow-task.sh &
jobs -l
disown -h %1
disown
jobs -l

SSH and Interactive Sessions

nohup is fine for one-off tasks; for repeatable admin work prefer a persistent multiplexer.

TipProduction long runners should be a systemd unit with Restart= and journal logging — not a forgotten nohup.
tmux
screen

nohup vs cron vs systemd

Match the tool to how often the job runs and how you need to observe failures.

one-off
schedule

Verify the Process

Confirm PID still exists and logs are growing before you log out.

bashcheck
ps -p $(cat /var/run/backup.pid) -o pid,cmd
 tail -f /var/log/backup.log
ps -p
tail -f

Quick Reference

  • nohup COMMAND >> log 2>&1 & survives SSH disconnect
  • Save PID with echo $! for monitoring
  • Services: use systemd, not eternal nohup

Related tutorials

Diagrams are original illustrations by Gnome IT Solutions. Tutorial text © Gnome IT Solutions.