0

Why is it not recommended to run mongod process as root as per the documentation?

  1. Is it only security that we run it as a non root user ?
  2. Will running as root cause any specific issues like Out of Memory issues that kill the mongod process?
2

It is best practise to run as little as possible as root, or any other account with significant privileges.

Each application or service should run with the lowest privilege set that will allow it to operate correctly, then if there is a problem (security bug in the service itself, security bug in the application software that uses the service, misconfiguration by your installation, …) the potential damage is limited by the service having limited privileges.

Running as root might reduce the chance of the process getting killed in low memory situations but only if something else gets killed instead (processed owned by root get a lower “kill candidate” score) so you will still have stability issues with other parts of the system. And it still might get killed anyway, if there is nothing else to get rid of first or the other candidates that come first are too small to make a real difference. If you are living in fear of OOM conditions though you either need some combination of:

  • To configure the service to limit the memory it will use.
  • Stop running other things, that might compete for memory, on the same node(s).
  • Add more RAM (bare metal) or assign more (VM).

rather than trying tricks like running services as root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.