Interview Prep/Linux/Users, groups and access control

You must give the monitoring agent permission to read every process's `/proc/<pid>/` info and bind to port 162 without running as root. How?

AdvancedScenarioUsers, groups and access control
Answer

Situation read → Use Linux capabilities instead of root.

What I'd do →

  1. In the systemd unit:
[Service]
User=monagent
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SYS_PTRACE CAP_DAC_READ_SEARCH
NoNewPrivileges=yes
  1. systemctl daemon-reload && systemctl restart monagent.
  2. Verify: grep Cap /proc/$(pidof monagent)/status | xargs and decode with capsh --decode=....

Why → Capabilities split root into small privileges; the bounding set guarantees the process can never gain more.

Interview tip → Prefer AmbientCapabilities in systemd over setcap on the binary, because file caps get lost on package upgrades.

All Linux questions Roadmap: Linux

More on Users, groups and access control