Linux Labs

Server security / Stage 7 of 10

A service with least privilege

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 6 · summary · 2 min

Summary

  • A unit without User= runs as root; a separate account in User= takes away the powers a service does not need.
  • ProtectSystem=strict, ProtectHome=yes and NoNewPrivileges=yes close the disk, home directories and privilege escalation without touching the code.
  • systemd-analyze security <unit> scores the restrictions, and --threshold=N is made for a check in a script.
  • A service with a narrow task gets one capability (CAP_NET_BIND_SERVICE) instead of all of root's power.
  • lab-preview from the start of the lesson read /etc/shadow only because it ran as root: User=preview closed that access off.
Ubuntu 24.04
Loading…