By default, mongo runs with user auth disabled.
To enable it, do the following:
Create admin user
First, connect to admin database and create "admin" user (it can be named anything, does not necessarily need to be called "admin"):
![](https://lxadm.com/content/images/2022/09/Ekran-Resmi-2022-09-21-18.08.46.png)
Enable user auth in mongod.conf and restart mongod
In /etc/mongod.conf, make sure the following is present and restart mongod:
![](https://lxadm.com/content/images/2022/09/Ekran-Resmi-2022-09-21-18.08.53.png)
Connect to mongo shell with auth enabled
![](https://lxadm.com/content/images/2022/09/Ekran-Resmi-2022-09-21-18.09.00.png)
Create a non-admin user for database access
This one will create "phpunituser" with "readWrite" access to "phpunitdb" database. Make sure "use phpunitdb" is present before db.createUser(...):
![](https://lxadm.com/content/images/2022/09/Ekran-Resmi-2022-09-21-18.09.06.png)
Connect to mongo shell as non-admin user
![](https://lxadm.com/content/images/2022/09/Ekran-Resmi-2022-09-21-18.09.15.png)