Agent Wranglers

OPS-32Required

Run each service as its own user

Run every service as a dedicated user with no login, that owns only its own data and can read only what it needs.

How to do it

Create one system user per service, never root and never the web server's user. Make its data folder readable only by that user, for example with mode 700. The security testing playbook covers keys and database accounts.

Examples

Shell example

useradd --system --no-create-home --shell /usr/sbin/nologin shop
install -d -o shop -g shop -m 700 /var/lib/shop

How to check

ps -o user= -p "$(systemctl show -p MainPID --value shop)" prints the service user, not root. sudo -u nobody ls /var/lib/shop fails with permission denied.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/operations/running-the-service/service-user">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.