Stop systemd from killing your background tasks when you log out

Systemd & Service Management

Stop systemd from killing your background tasks when you log out

Technical Briefing | 12/5/2026

You probably think your long-running script or screen session is safe once you detach and exit your SSH connection. Most of the time, you are right. But every so often, you return to find your processes dead, leaving you to sift through log files wondering why your task died mid-execution. It turns out that systemd, specifically the lingering behavior of user sessions, is the culprit here.

Why your session dies when you leave

When the last session for a user ends, systemd performs a clean sweep. It kills every process associated with that user session to prevent orphans from hanging around and consuming resources. If you have services managed by user-level systemd instances, they should survive, but anything started manually in a shell or a legacy screen session often gets caught in the crossfire of KillUserProcesses=yes.

loginctl enable-linger yourusername

  • Enabling linger creates a systemd user manager that persists regardless of active sessions.
  • Your services will now start automatically at boot without requiring you to log in first.
  • Check /var/lib/systemd/linger to verify which users are currently set to persist.

Testing the persistence

Don’t just take the documentation’s word for it. After enabling linger, try launching a simple long-running task, kill your shell, and log back in from a fresh session. If you see your process still humming along while the rest of the user scope is freshly initialized, you have fixed the issue. Just keep in mind that this bypasses the standard clean-up mechanism, so be careful about what you leave running in the background indefinitely.

Linux Admin Automation  |  © www.ngelinux.com  |  12/5/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted