I want to run mongodb service by my defined username and group instead of using mongodb user. How can i change from
mongodb user to
If you're running
mongodb as a service, you would need to edit the
upstart configuration file:
- Change the argument
--chuid mydesiredusername. If you need to specify a group, use
- Restart by running
sudo restart mongodb.
You might also need to change the ownership of your database files (in
/var/lib/mongodb unless you have changed that as well) and the
/var/log/mongodb directory and its contents so that
mongodb can still read and write to its files.
You don't explain why you want to make this change, so maybe you have a good reason. But I would suggest keeping to the default user and finding an alternative solution to the problem you are trying to solve. Services run as their own user for good reasons, not least for security. Changing something like this can cause unexpected problems in the future, make upgrades harder, and is also confusing if other people need to administer your server at a later date.