Stop hunting for hidden lingering processes after a user logs out
User & Group Management
Stop hunting for hidden lingering processes after a user logs out
🧩 The Challenge
Every once in a while, a developer claims they pushed a script, but the production logs show the old process is still chugging away. Even after I kill their SSH session, some background process keeps holding onto their UID.
💡 The Fix
Use loginctl to identify and terminate lingering sessions that refuse to die when the shell exits. It stops those invisible ghost processes that keep zombie jobs running long after the user thinks they’ve logged out.
loginctl list-sessions
loginctl terminate-user username
⚙️ Why It Works
Systemd creates session tracking for every login, but if a process spawned a background job that didn’t properly detach or clean up, it stays attached to the session scope. Forcing the termination of that user scope nukes everything associated with their ID instantly.
🚀 Pro-Tip: Check /etc/systemd/logind.conf to set KillUserProcesses=yes if you want this to be the default behavior.
Linux Tips & Tricks | © ngelinux.com | 9/17/2026
