Linux Systemd Service Persistence
A systemd service configured to start on boot gives persistent code execution that runs before any user logs in, as root, and restarts automatically on failure. It blends in with the hundreds of legitimate services on any modern Linux system and is not visible in crontab listings.
Create a persistent systemd service
Restart=always with RestartSec=30 means the service restarts 30 seconds after it exits or is killed. This makes the persistence resilient against the payload crashing or being terminated manually. Use After=network.target to ensure network connectivity is available before the payload runs.
User-level systemd services
User-level services run under a specific user's systemd instance without requiring root. They persist as long as the user account exists and start when the user logs in — or with lingering enabled, on boot.
Hijack an existing service
Rather than creating a new service, modifying an existing low-priority service's ExecStart or adding an ExecStartPre directive runs your payload alongside a legitimate service. This is harder to detect than a new unknown service name.
Drop-in files in /etc/systemd/system/servicename.service.d/ override or extend the original unit without touching it. The original service file stays clean — only the drop-in directory reveals the modification.
Cleaning up
Was this helpful?
Your feedback helps improve this page.