systemd¶
Tested with systemd 255 on Ubuntu 24.04.
A unit that actually restarts on failure¶
[Unit]
# Without this, repeated crashes hit the start limit (5 starts in 10 s) and
# systemd gives up: the unit sits in "failed" until someone looks.
StartLimitIntervalSec=0
[Service]
Restart=always
RestartSec=2
TimeoutStopSec=30
StartLimitIntervalSec must be in [Unit]. In [Service] systemd ignores it
and the limit stays at 10 seconds: in a test, the unit gave up after 5
restarts with the line in [Service], and kept restarting with it in
[Unit]. Check what is actually in effect:
How exposed is each service?¶
systemd-analyze security # every service, scored 0 (locked down) to 10
systemd-analyze security ssh.service # one service, every setting explained
Most distribution units score "UNSAFE" or "EXPOSED". The per-service view
lists the hardening options (ProtectSystem=, NoNewPrivileges=,
PrivateTmp= …) that would lower the score; add them in a drop-in with
systemctl edit, one at a time, and restart to check nothing breaks.