With which user should I run web servers, redis & mongodb

Securityuserswebserver

On this VPS there are three users: root, another_one, nobody. All webserver files, configs, &c. are owned by root. However, I'm in doubt for what regards running things. If I use root for the web server I may expose the system to security holes, whereas if I try to login into nobody it asks me a password which I never set and I don't know. Should I create yet another user?

For now I'm only sure about nginx: I run it as root and it spawns processes as nobody. But what about web servers and other services like db and redis?

Note: I should mention that another_user can sudo, so it's not that different from root.

Best Answer

I always run services with a dedicated user. So I would create these users:

  • nginx
  • mongo
  • apache
  • mysql
  • redis

You should never run the actual services as root!

Often when installing these applications using your distributions package manager, as part of the installation, a user will be automatically created for each of these services.

I typically use CentOS/RHEL and when I install things like Apache, the user "apache" is created automatically at that point. So too for MySQL, and Nginx.

Related Question