Operations 6 min read

How to Keep Linux Scripts Running After Logout Without systemd

This guide explains multiple techniques—nohup, disown, setsid, tmux, screen, and at—to run scripts in a Linux environment so they continue executing after the user logs out, providing command examples, usage details, and a comparison of terminal multiplexers for reliable background processing.

Ops Development & AI Practice
Ops Development & AI Practice
Ops Development & AI Practice
How to Keep Linux Scripts Running After Logout Without systemd

Background

When developing scripts on Linux it is often necessary to keep a process running after the user logs out, without relying on systemd or other heavyweight init systems.

Using nohup

nohup

runs a command immune to the SIGHUP signal. By default the command’s standard output and error are written to nohup.out, but the output can be redirected.

nohup ./my_script.sh &
nohup ./my_script.sh > my_script.log 2>&1 &

Using disown

disown

removes a background job from the shell’s job table, preventing it from receiving SIGHUP on logout.

./my_script.sh &
 disown

It can be combined with nohup for extra safety:

nohup ./my_script.sh &
 disown

Using setsid

setsid

creates a new session and runs the program inside it, fully detaching the process from the controlling terminal.

setsid ./my_script.sh &

Using tmux

tmux

is a terminal multiplexer that can create a detached session, run a command inside it, and later re‑attach.

tmux new-session -d -s my_session './my_script.sh'

Re‑attach when needed:

tmux attach-session -t my_session

Using screen

screen

provides similar functionality to tmux. screen -dmS my_session ./my_script.sh Re‑attach later:

screen -r my_session

Using at

The at utility schedules a one‑time job. Ensure the atd daemon is running, then submit the script for immediate execution.

sudo systemctl start atd
echo "./my_script.sh" | at now

Comparison of tmux and screen

Session management : Both allow creation, detachment, and re‑attachment of sessions.

Window/pane splitting : tmux supports multiple panes within a single window, useful for parallel tasks.

Script friendliness : tmux offers richer command‑line options for automation.

Stability and community : screen is older and widely deployed; tmux has a more active development community and more configurable defaults.

Recommendation

All the methods above keep a script alive after logout. For ad‑hoc or one‑off tasks, nohup, disown, or setsid are sufficient. For long‑running or interactive workloads, a terminal multiplexer is preferable; tmux is generally recommended because of its modern feature set, flexible configuration, and active support, while screen remains a solid fallback.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

process managementLinuxscreentmuxatnohupdisown
Ops Development & AI Practice
Written by

Ops Development & AI Practice

DevSecOps engineer sharing experiences and insights on AI, Web3, and Claude code development. Aims to help solve technical challenges, improve development efficiency, and grow through community interaction. Feel free to comment and discuss.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.