[ACCEPTED]-MongoDB only works when run as root on Ubuntu - data directory issue-chown

Accepted answer
Score: 75

You created /data/db as root so it has those permissions. You 6 can change the permissions to your user 5 account, or whatever you have mongo running 4 as.

chown -R username /data/db

or /data

You can also set a group

chown -R username.groupname

The -R does 3 it recursively, so it will affect all the 2 files you've created running mongoDB as 1 root already.

Score: 1

I just had the same issue on RHEL 8, in 6 year 2021.

I could run sudo mongod with sudo privileges 5 but could not start it as a service with: sudo systemctl start mongod.

I 4 tried many solutions and tested after each 3 attempt, what ultimately solved it for me 2 is changing ownership of /data/db/, /var/lib/mongo/, and /var/log/mongodb/ to mongod.

exact 1 commands:

sudo chown -R mongod:mongod /var/lib/mongo/
sudo chown -R mongod:mongod /var/log/mongodb/
sudo chown -R mongod:mongod /data/

More Related questions