Kestrel Docs

Practical Systemd Service Hardening

Modern systemd ships with expressive sandboxing primitives built on Linux namespaces, seccomp-bpf, and capabilities. Applying a minimal hardening block to network-facing services drastically reduces post-exploitation impact without container overhead.

Drop-in Hardening Template

[Service]
DynamicUser=yes
NoNewPrivileges=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=strict
ProtectHome=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
RestrictNamespaces=yes
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
SystemCallFilter=@system-service

Auditing Exposure

Use systemd-analyze security <unit> to inspect the computed exposure score (0.0 to 10.0, lower is better) and identify remaining filesystem or syscall permissions that can be tightened.