Mongod was not started by the correct user - remember NOT to run mongod as root

I have set up mongod configuration file with the following:

dbPath: /var/mongodb/db/
enabled: true




where to write logging data.

destination: file
logAppend: true
path: /var/log/mongodb/mongod.log

network interfaces

port: 27000
bindIp: “,”

how the process runs

timeZoneInfo: /usr/share/zoneinfo
fork: true

authorization: enabled

I then added the user successfully.

Successfully added user: {
“user” : “m103-admin”,
“roles” : [
“role” : “root”,
“db” : “admin”

Then I start the db successfully with mongod --config test.mongodb.conf and enter validation code.

And get error “Mongod was not started by the correct user - remember NOT to run mongod as root.”

Hi Ross_91055,

Few things you can check:

  • Check the owner of directory /var/mongodb/db. It should be vagrant:vagrant

  • I would make sure that my logs are in the same directory as dbPath: /var/mongodb/db/

  • Make sure you are in vagrant box. And user shows as vagrant:


  • Next restart your mongod by shutting down server:

    use admin

  • Now restart your mongod just you did before:

    vagrant@m103:~$ mongod --config mongodb.conf

I hope it helps!


1 Like

@Ross_91055: did you perhaps run the mongod through sudo? Or did you perhaps start a root shell at some point in time?

Hi Ross_91055,.

If this is the case that you have started the mongod with root or using sudo. I would recommend you to clear out the directory and create again.

Then start mongod without sudo.



How does one check the ownership of a directory?

cd to the path where dir was created.
ls -lrt
ls -ld directory

1 Like

Hi @Rodrigo_Alonso_30601,

I hope you found the post #6 helpful. If you still have any query then please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer


after connect with vagrant ssh, when I do ls -lrt it shows:

drwxrwxrwx 2 vagrant vagrant    4096 Nov 26 16:14 data
drwxrwxr-x 4 vagrant vagrant    4096 Nov 26 19:33 first_mongod
-rw-r--r-- 1 root    root    4366336 Nov 27 19:42 products.part2.json.tgz
drwxrwxr-x 2 vagrant vagrant    4096 Nov 27 21:06 sudo
drwxrwxr-x 3 vagrant vagrant    4096 Nov 27 22:08 var

which I understand is ok, because var is not on root. But then I run sudo mongod --config ../../shared/mongod.cfg
and keep getting the Mongod was not started by the correct user - remember NOT to run mongod as root.

please help

Hi @Rodrigo_Alonso_30601,

I’ve highlighted the main points. The main question here is, what is sudo? As a MongoDB student, suggest you research what sudo actually does. Once you know what it does, you’ll need to shutdown your server and restart it with the right commands.

Note that there’s nowhere in this course where mongod was started using sudo.


Ok, but when I run the command without super-user credentials it gets back to Failed global initialization: FileNotOpen: Failed to open "/var/mongodb/db/mongo.log" error.

I tried deleting the file, but then I get Failed global initialization: FileRenameFailed: Could not rename preexisting log file "/var/mongodb/db/mongo.log" to "/var/mongodb/db/mongo.log.2019-11-28T20-42-27"; run with --logappend or manually remove file: Permission denied tried again, using --append, deleting the file, but get stuck in the cycle…

Change the owner of all the files and directories under /var/mongodb/db/ to vagrant. You might need sudo to do it as the files are owned by root.

Hi @Rodrigo_Alonso_30601,

As others have mentioned, you are getting the error because of the permission issue.

Please run this command for changing the ownership of the directory.

sudo chown vagrant:vagrant /var/mongodb/db/ 

Hope it helps!

If you have any other query then please feel free to get back to us.

Shubham Ranjan
Curriculum Support Engineer

Thanks, but I get now Aborted (core dumped) I thing I must run sudo mongod --repair --dbpath /path/to/mongodb but I’m not sure where to find the appropiate path to mongodb

What did you run? Show us the screenshot of the command and the full error message.

Hi, this is it

Two things:

  1. Run this:
    ls -l /var/mongodb
  2. Screenshot of your mongod.cfg file

Ok, I ran the command, it shows this

but the error persist. My mongod.cfg files is:


I asked you to run the command so that I can see the permissions of the folder. It wasn’t to solve anything.

  1. Run the following
    rm -r /var/mongodb/db
    sudo chown -R vagrant:vagrant /var/mongodb
    mkdir -p /var/mongodb/db
  2. Under systemlog in the config file, add this line: logAppend: true

Run mongod again and let’s see the result. And if it fails, let’s see the contents of the log file.

All working well now, thanks!

Very good! :+1: :beers: