Interview Prep/Linux/Permissions, ownership, SELinux and mounts

`sudo -u app touch /var/log/app/x.log` works, but the app itself (running as `app` under systemd) gets `EACCES` on the same path.

AdvancedTroubleshootingPermissions, ownership, SELinux and mounts
Answer

Likely causes → systemd sandboxing: ProtectSystem=strict makes /var read-only unless listed in ReadWritePaths=, or ProtectHome, PrivateTmp, or an SELinux domain differs between the shell and the service.

Diagnose →

systemctl show app -p ProtectSystem -p ReadWritePaths -p ProtectHome
systemctl cat app
sudo ausearch -m AVC -ts recent

Fix → Add ReadWritePaths=/var/log/app (or LogsDirectory=app, which creates and permits /var/log/app), then daemon-reload and restart.

Prevent → Use StateDirectory=, LogsDirectory=, RuntimeDirectory= instead of hand-made directories.

All Linux questions Roadmap: Linux

More on Permissions, ownership, SELinux and mounts