Configuring MongoDB security in Ubuntu 20.04

17.12.2022
13:13

To configure MongoDB security on Ubuntu 20.04, you need to create a user with admin rights, configure authentication and test it. MongoDB (Mongo) is a database that belongs to NoSQL and stores JSON with dynamic schemas.

Why you need to configure MongoDB security in Ubuntu 20.04

Mongo's security problem is that there is no authentication out of the box. Any user accessing the server with the database can add and delete data without restriction. This has a serious impact on security. For this reason, to protect against the MongoDB vulnerability in Ubuntu 20.04 you need to:

  • create a user with admin rights and access to the database;
  • enable authentication;
  • check authentication using tests.

What is needed to configure Mongo security

1, MongoDB database on the server.

2. Ubuntu 20.04 server without root users but with a firewall.

Step by step instructions for configuring MongoDB security:

Add a user with admin privileges. You can do this without additional settings, since authentication is disabled by default. Create the user with the db.createUser command. Basically, you form a JSON file with data (name, password, role). After creating the user, exit the MongoDB client using the exit command

Activate authentication in MongoDB config file mongod.conf. To do this, find security in the configs and select

security:

authorization: "enabled"

To activate the changes in the configs, restart the daemon.

At the final stage check Mongo authentication settings. You can check access restrictions using the show dbs command. If the authentication of the user with the previously set rights is not performed, the system will not give access to the database.

15% discount on new VPS
Hurry up to order a server in any location
Choose a VPS

Other articles

07.03.2021
5 764
Knowledge base / Instructions
How to set up FTP on Ubuntu 20.04 LTS
07.03.2021
5 455
Knowledge base / Instructions
How to secure Apache with Let's Encrypt on CentOS Stream
07.03.2021
5 154
Knowledge base / Instructions
How to install LAMP stack on CentOS Stream server