> For the complete documentation index, see [llms.txt](https://docs.enginsight.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enginsight.com/docs/knowledge-base/english/database/how-do-i-set-up-a-password-for-the-enginsight-database.md).

# How do I set up a password for the Enginsight database?

Enginsight uses MongoDB as its database. By default, it is not protected with a password. In the following, we will show you the steps that are required to protect the MongoDB system database `admin` and the Enginsight database via username and password (role-based access control; RBAC).

{% stepper %}
{% step %}

### Stop the Enginsight Application Server

1. Log in to the **Application Server**.
2. Navigate to the Enginsight installation directory using the following command:

```
cd /opt/enginsight/enterprise
```

2. Now stop the Application Server using the following command:

```
sudo docker-compose down
```

{% hint style="danger" %}
**Please note**: This step is *mandatory* before making any changes to the database.
{% endhint %}
{% endstep %}

{% step %}

### Open the MongoDB shell

1. Log in to the **Enginsight Database Server**.
2. Open the **MongoDB shell** using the following command:

```
sudo mongosh
```

{% endstep %}

{% step %}

### Navigate to the admin system database

Navigate to the `admin` system database using the following command:

```
use admin
```

{% endstep %}

{% step %}

### Create an administrator user account

Enter the following command to create an administrator user account with a username and password for the database:

```
db.createUser(
  {
    user: "mongoAdminUser",
    pwd: "<MongoAdminUserPassword>",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)
```

{% hint style="info" %}
Remember to replace `<MongoAdminUserPassword>` with a password of your choice.
{% endhint %}
{% endstep %}

{% step %}

### Add the required role

1. Enter the following command to add the role that the new administrator user needs in order to view the status of the MongoDB replica set:

```
db.grantRolesToUser(
  "mongoAdminUser",
  [
    { role: "clusterMonitor", db: "admin" }
  ]
)
```

2. Close the MongoDB shell using the following command:

```
quit ()
```

{% endstep %}

{% step %}

### Open the MongoDB configuration file

Open the **MongoDB configuration file** `mongod.conf` using the following command:

```
sudo nano /etc/mongod.conf
```

{% endstep %}

{% step %}

### Extend or adjust the `security` section

1. Add the `security` section as follows and/or adjust it accordingly to enable password authentication:

```
security:
    authorization: "enabled"
```

2. Save the configuration file (**Ctrl** + **o**) and confirm the save process. Close the file (**Ctrl** + **x**).
   {% endstep %}

{% step %}

### Restart the database service

Restart the database service using the following command to apply the configuration changes:

```
sudo systemctl restart mongod
```

{% endstep %}

{% step %}

### Log in to the database as an administrator

Now log in to the database as an administrator using the following command:

```
sudo mongosh 'mongodb://mongoAdminUser:<MongoAdminUserPassword>@<DatabaseServerIPAddress>:27017/admin?authSource=admin&replicaSet=rs0'
```

{% hint style="info" %}
Remember to replace `<MongoAdminUserPassword>` with the password you assigned earlier for the administrator user account, and replace `<DatabaseServerIPAddress>` accordingly.
{% endhint %}
{% endstep %}

{% step %}

### Navigate to the Enginsight database

Now navigate to the Enginsight database using the following command:

```
use enginsight
```

{% endstep %}

{% step %}

### Create a user for the Enginsight database

1. Enter the following command to create a default user account with a username and password for the Enginsight database:

```
db.createUser(
  {
    user: "mongoDefaultUser",
    pwd: "<MongoDefaultUserPassword>",
    roles: [ { role: "readWrite", db: "enginsight" } ]
  }
)
```

{% hint style="info" %}
Remember to replace `<MongoDefaultUserPassword>` with a password of your choice.
{% endhint %}

2. Close the MongoDB shell using the following command:

```
quit ()
```

{% endstep %}

{% step %}

### Apply the changes on the Enginsight Application Server

1. Go back to the Application Server and navigate to the Enginsight installation directory using the following command:

```
cd /opt/enginsight/enterprise
```

2. Run the setup script for the Application Server anew using the following command:

```
sudo ./setup.sh
```

3. When prompted for the URIs and URLs, enter the **MongoDB URI** as follows:\
   `mongodb://mongoDefaultUser:<MongoDefaultUserPassword>@<DatabaseServerIPAddress>:27017/enginsight?authSource=enginsight&replicaSet=rs0`

{% hint style="info" %}
Remember to replace `<MongoDefaultUserPassword>` and `<DatabaseServerIPAddress>` accordingly.
{% endhint %}
{% endstep %}
{% endstepper %}

***
