Services (.service)

Run a long-running program as a user service (no root)

3 min read

You don’t need root (or /etc/systemd/system/) to run your own background program. Each user gets a private systemd instance.

The user unit

Save as ~/.config/systemd/user/mybot.service (no sudo):

[Unit]
Description=My personal bot

[Service]
ExecStart=%h/apps/bot/run
Restart=on-failure
RestartSec=5

[Install]
WantedBy=default.target

Enable and start (no sudo)

systemctl --user daemon-reload
systemctl --user enable --now mybot.service
systemctl --user status mybot.service
journalctl --user -u mybot.service -f

Keep it running after logout (lingering)

By default a user’s services stop when their last session ends. To let them start at boot and keep running with no active login, enable lingering once:

sudo loginctl enable-linger "$USER"

Check it with loginctl show-user "$USER" -p Linger.


Why user units: no root, no touching system directories, and a clean blast radius — great for personal bots, sync jobs, dev servers, or anything scoped to one account. Gotchas: user units can’t depend on system units directly, and enable-linger is what makes them autostart at boot; without it they only run while you’re logged in.

Open the full version (with copy buttons) ↗

← All recipes