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.
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
nohupruns 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
disownremoves a background job from the shell’s job table, preventing it from receiving SIGHUP on logout.
./my_script.sh &
disownIt can be combined with nohup for extra safety:
nohup ./my_script.sh &
disownUsing setsid
setsidcreates a new session and runs the program inside it, fully detaching the process from the controlling terminal.
setsid ./my_script.sh &Using tmux
tmuxis 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_sessionUsing screen
screenprovides similar functionality to tmux. screen -dmS my_session ./my_script.sh Re‑attach later:
screen -r my_sessionUsing 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 nowComparison 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
