Mastering nohup: Keep Your Linux Jobs Alive After Logout or SSH Disconnect
When you close an SSH session or accidentally lose your terminal connection, any processes running in that session typically receive a…
Mastering nohup: Keep Your Linux Jobs Alive After Logout or SSH Disconnect

When you close an SSH session or accidentally lose your terminal connection, any processes running in that session typically receive a SIGHUP (Signal Hang Up) signal, causing them to terminate immediately. This can be frustrating if you’re running long tasks or deployments that you expect to continue even after you disconnect.
The **nohup (no hang up)** command solves this problem by blocking the SIGHUP signal and allowing your processes to continue running safely in the background—even after you log out.
This guide walks through everything you need to know about nohup on Linux, including its syntax, practical examples, process management tips, and best practices.
Why Use nohup for Background Processes?
nohup provides several advantages for long-running or critical jobs:
- Prevents premature termination — processes won’t stop if you log out or disconnect.
- Avoids wasted compute time — no need to restart tasks from scratch if your session ends.
- Ideal for remote work — resilient against unexpected SSH drops.
- Detaches jobs cleanly — allows you to disown processes from your terminal session.
- Ensures persistence — lets jobs run to completion even after you log off.
In short, nohup lets you start tasks with confidence, knowing they’ll finish regardless of terminal state.
Nohup Command Syntax
The basic syntax is:
nohup COMMAND [OPTIONS]
Common options:
--help– display usage information--version– show the installednohupversion-v, --verbose– enable detailed output (useful for debugging)-p, --prefix PREFIX– specify a prefix path for thenohup.outfile
How to Use nohup
- Run a basic command with
nohup
nohup bash example.sh
- Run in the background
Append an ampersand (&) to detach the process from your terminal:
nohup bash example.sh &
- Redirect output to a custom file
By default, nohup writes output to nohup.out. You can redirect it elsewhere:
nohup bash example.sh > output.txt
- Run multiple commands sequentially
Use bash -c with a string of commands separated by &&:
nohup bash -c 'command1 && command2'
How to Terminate a nohup Process
- Find the process ID (PID) using
psandgrep:
ps aux | grep "<pattern>"
a– show processes for all usersu– show detailed process info (user, CPU%, memory%, etc.)x– include processes without a controlling terminal|– pipe output into another commandgrep– filter for a specific keyword (e.g.,apache,8007)
- Kill the process using its PID:
kill <PID>
Practical nohup Use Cases
Example: Keep a Django Development Server Running
# Start the server and detach it
nohup python3 manage.py runserver 0.0.0.0:8007 &

# Find the running process
ps aux | grep "8007"

# Kill the process when done
kill 943507
Key Takeaways
**nohupprevents your jobs from dying when your SSH session closes.**- Always redirect output if you want cleaner logs.
- Combine with
&to run jobs fully in the background. - Use
ps aux | grepto locate processes andkillto terminate them.
With these techniques, you can safely log out or disconnect from your SSH session while ensuring your tasks keep running to completion.
메타데이터
- post_id
- 50b9bca83aeb
- slug
- mastering-nohup-keep-your-linux-jobs-alive-after-logout-or-ssh-disconnect-50b9bca83aeb
- url
- https://medium.com/@hecate_he/mastering-nohup-keep-your-linux-jobs-alive-after-logout-or-ssh-disconnect-50b9bca83aeb
- canonical_url
- https://medium.com/@hecate_he/mastering-nohup-keep-your-linux-jobs-alive-after-logout-or-ssh-disconnect-50b9bca83aeb
- author_url
- https://medium.com/@hecate_he
- status
- ok
- fetched_at
- 2026-06-26 21:52:29