Skip to main content
Version: 7.0

Authorization configuration in Linux

Connecting and creating user in MongoDB

Connecting to the shell

Connect to the MongoDB shell:

mongosh

Creating user

Switch to the admin database:

use admin

Create a user by changing the login (user) and password (pwd):

db.createUser({
user: "adminuser",
pwd: "password",
roles: [
{ role: "root", db: "admin" }
],
passwordDigestor: "server"
})
danger

The following characters are prohibited in the username and password as they may cause connection failures to MongoDB: . @ $ : % " ' / \ |

Enabling authorization and connecting Passwork

Enabling authorization in MongoDB

Edit the MongoDB configuration file to enable authorization by running the following commands in the shell to find its location:

var cmdLineOpts = db.serverCmdLineOpts();
print("config: " + cmdLineOpts.parsed.config);

Edit the obtained configuration file by modifying and adding the following lines:

security:
authorization: enabled

Example of the edited file

Example of edited MongoDB configuration file
danger

Note that indentation is a critical detail of the configuration file syntax.

Save the changes and restart the MongoDB service:

systemctl restart mongod.service

To verify, connect to the shell with authorization:

mongosh "mongodb://adminuser:password@localhost:27017"

Configuring and connecting Passwork with authorization

Edit the Passwork configuration file /var/www/init/config.env, specifying the username and password of the created user:

MONGODB_USERNAME=adminuser
MONGODB_PASSWORD=password

Save the changes and refresh the Passwork page to verify the connection with MongoDB authorization.