How to Install MongoDB 9.0 on Red Hat (RHEL) 10 and Allow Remote Access

Add the official MongoDB repository to a Red Hat (RHEL) 10 server and install MongoDB 9.0, create an admin user and a de…

RHEL 10MongoDB 9.0x86_64About 9 min

Verified guide

This guide was verified by creating a cloud server and running every command in it, from start to finish, exactly as written.

OS
Red Hat Enterprise Linux 10.2 (Coughlan) · x86_64
Installed version
MongoDB 9.0.4 (mongodb-org 9.0.4-1.el10), mongosh 2.14.0
Test server
Microsoft Azure · 1 vCPU / 2 GB RAM / 64 GB SSD (Standard_F1als_v7, koreacentral, RedHat:RHEL:10_2-gen2 PAYG)
Last checked
2026-10-26

Add the official MongoDB repository to a Red Hat (RHEL) 10 server and install MongoDB 9.0, create an admin user and a dedicated user for applications and turn on authentication, and then configure remote access and the firewall (firewalld) so that only your PC can connect.

1. Requirements

  • One Red Hat Enterprise Linux 10 server (x86_64, a CPU that supports AVX)
  • SSH access with an account that has sudo privileges
  • The public IP address of the PC you will connect from (e.g. 203.0.113.10)
  • Docker on the PC you will use to check the connection (not needed if mongosh is installed on your PC)

Every step in this guide was verified on a server created as a Microsoft Azure virtual machine (1 vCPU · 2 GB memory · Standard_F1als_v7 · RHEL 10.2 pay-as-you-go image · Korea Central). Azure's pay-as-you-go RHEL images receive packages from the cloud provider's repositories (RHUI) without registering a Red Hat subscription.

According to the official MongoDB Production Notes, MongoDB 5.0 and later require a CPU that supports AVX instructions on x86_64 servers. The command below displays the number of CPU cores that support AVX. If it is 1 or more, you can install MongoDB. If it is 0, MongoDB cannot run on this server.

grep -c avx /proc/cpuinfo
1

2. Add the official MongoDB repository

Install MongoDB from the official MongoDB repository (repo.mongodb.org). Create the repository configuration file. The 10 in baseurl means the repository for RHEL 10, and gpgkey is the address of the signing key used to check that the packages were made by MongoDB.

sudo tee /etc/yum.repos.d/mongodb-org-9.0.repo <<EOF
[mongodb-org-9.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/10/mongodb-org/9.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-9.asc
EOF

3. Install MongoDB 9.0

Installing the mongodb-org package installs the server (mongod), the connection tool (mongosh) and the backup tools (mongodump and others) together.

On the first installation, a message about importing the signing key is displayed. If you see Key imported successfully, it is working.

sudo dnf install -y mongodb-org
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.
…
Importing GPG key 0x602E502D:
 Userid     : "MongoDB 9 Release Signing Key <packaging@mongodb.com>"
 Fingerprint: B3B4 2B6C 39E5 CDDE C0A2 7E3C F366 D55B 602E 502D
 From       : https://pgp.mongodb.com/server-9.asc
Key imported successfully
…
Complete!

The This system is not registered with an entitlement server at the top is a notice that this server is not registered with a Red Hat subscription. Pay-as-you-go RHEL images on clouds such as Azure receive packages from the cloud provider's repositories (RHUI), so the installation continues even when this message appears. If you installed RHEL yourself with a subscription, register it with subscription-manager before installing.

Check the installed version.

mongod --version
db version v9.0.4
mongosh --version
2.14.0

4. Start the service and check its status

On RHEL, the installation registers the service to start automatically when the server restarts (enabled), but the service does not start right away.

sudo systemctl status mongod --no-pager
○ mongod.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: disabled)
     Active: inactive (dead)
       Docs: https://docs.mongodb.org/manual

Start the service.

sudo systemctl start mongod

If active (running) is displayed, it is working.

sudo systemctl status mongod --no-pager
● mongod.service - MongoDB Database Server
     Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; preset: disabled)
     Active: active (running) since Mon 2026-10-26 06:50:41 UTC; 3s ago

On RHEL 10, SELinux is also turned on in enforcing mode (Enforcing). The RHEL 10 server used to verify this guide had no SELinux rules for MongoDB, so mongod ran as an unconfined service (unconfined_service_t) and worked without extra settings. Check that SELinux has not blocked anything. If <no matches> is displayed, nothing was blocked.

sudo ausearch -m avc -ts today
<no matches>

If you change the data or log path from the default, SELinux may block access. In that case, follow the SELinux policy settings in the official MongoDB documentation.

Check which addresses MongoDB accepts connections on. Only 127.0.0.1:27017 is displayed, so for now you can connect only from the server itself.

sudo ss -tlnp | grep 27017
LISTEN 0      4096       127.0.0.1:27017      0.0.0.0:*    users:(("mongod",pid=7848,fd=9))

5. Check the connection with mongosh

Connect to the server with mongosh and check the response. --eval is an option that runs only the one command written after it and then exits, and --quiet is an option that hides the connection messages. If { ok: 1 } is displayed, it is working.

mongosh --quiet --eval "db.runCommand({ ping: 1 })"
{ ok: 1 }

6. Create an admin user and turn on authentication

Right after installation, MongoDB lets anyone read and write all data without user authentication. Before you open remote access, create an admin user and turn on authentication. passwordPrompt() is a function that asks for the password instead of having you write it in the command. The password you enter is displayed as *.

mongosh --quiet admin --eval 'db.createUser({ user: "admin", pwd: passwordPrompt(), roles: [ "userAdminAnyDatabase", "readWriteAnyDatabase" ] })'
Enter password
**************************{ ok: 1 }
  • userAdminAnyDatabase: Can create users and grant permissions on every database.
  • readWriteAnyDatabase: Can read and write data in every database.
  • Because this user is created in the admin database, authenticate with --authenticationDatabase admin when you connect.

In the configuration file /etc/mongod.conf, replace the commented-out #security: with the authentication setting.

sudo sed -i "s/^#security:/security:\n  authorization: enabled/" /etc/mongod.conf
grep -n -A1 "^security:" /etc/mongod.conf
26:security:
27-  authorization: enabled

Restart MongoDB. If active is displayed, it is working.

sudo systemctl restart mongod
sudo systemctl is-active mongod
active

Commands are now refused if you connect without authentication.

mongosh --quiet --eval "show dbs"
MongoServerError: Command listDatabases requires authentication

If you give the user name with -u and add -p without a value, you are asked for the password. If the list of databases is displayed, authentication is working.

mongosh -u admin -p --authenticationDatabase admin --quiet --eval "show dbs"
Enter password: **************************
admin   100.00 KiB
config   12.00 KiB
local    40.00 KiB

7. Create a dedicated user for applications

It is safer for applications to connect as a dedicated user that can use only one database, instead of the admin user. Create appuser, which can only read and write the appdb database. You enter a password twice. The first is the admin password, and the second is the password for the new appuser.

mongosh -u admin -p --authenticationDatabase admin --quiet appdb --eval 'db.createUser({ user: "appuser", pwd: passwordPrompt(), roles: [ { role: "readWrite", db: "appdb" } ] })'
Enter password: **************************
Enter password
********************{ ok: 1 }

Connect as appuser, then store and read data. The /appdb at the end of the connection address is the database to connect to. Because appuser was created in this database, authentication also uses this database.

mongosh "mongodb://localhost:27017/appdb" -u appuser -p --quiet --eval 'db.items.insertOne({ name: "hello" })'
Enter password: ********************
{
  acknowledged: true,
  insertedId: ObjectId('6adef865f828b34bda0b8877')
}
mongosh "mongodb://localhost:27017/appdb" -u appuser -p --quiet --eval "db.items.find()"
Enter password: ********************
[ { _id: ObjectId('6adef865f828b34bda0b8877'), name: 'hello' } ]

Writing to a database that is not allowed is refused. If the error below is displayed, the permissions are applied as intended.

mongosh "mongodb://localhost:27017/appdb" -u appuser -p --quiet --eval 'db.getSiblingDB("otherdb").items.insertOne({ name: "hello" })'
Enter password: ********************
MongoServerError: not authorized on otherdb to execute command { insert: "items", documents: [ { name: "hello", _id: ObjectId('6adef86988e545abd16eea34') } ], ordered: true, lsid: { id: UUID("fb877191-af58-402c-ab21-5c83c3af1012") }, $db: "otherdb" }

8. Allow remote connections

The default settings allow only localhost connections. To allow remote connections, change bindIp in /etc/mongod.conf to 0.0.0.0. 0.0.0.0 means that MongoDB accepts connections on all of the server's IPv4 addresses.

sudo sed -i "s/^  bindIp: 127.0.0.1/  bindIp: 0.0.0.0/" /etc/mongod.conf
grep -n -A2 "^net:" /etc/mongod.conf
21:net:
22-  port: 27017
23-  bindIp: 0.0.0.0  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

Restart MongoDB and check that port 27017 is now open on external addresses as well. If you see 0.0.0.0:27017, it is working.

sudo systemctl restart mongod
sudo ss -tlnp | grep 27017
LISTEN 0      4096         0.0.0.0:27017      0.0.0.0:*    users:(("mongod",pid=9187,fd=9))

9. Configure the firewall (firewalld)

On RHEL 10, firewalld is turned on and allows only a few services such as SSH, so you cannot reach port 27017 from your PC yet. Add a rule so that only your PC's IP can reach port 27017. --permanent is an option that saves the rule so that it remains after the server restarts, and --reload applies the saved rules right away. /32 means that only one IP address is allowed.

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10/32" port port="27017" protocol="tcp" accept'
sudo firewall-cmd --reload
success
success

Check the rule you added.

sudo firewall-cmd --list-rich-rules
rule family="ipv4" source address="203.0.113.10/32" port port="27017" protocol="tcp" accept

If you use your cloud provider's network firewall (such as an Azure network security group), you also need to allow port 27017 for your PC's IP there. This guide was verified with ports 22 and 27017 allowed only for the PC's IP in an Azure network security group.

10. Check the connection from your PC

If mongosh isn't installed on your PC, you can connect by running the mongosh included in the official MongoDB image (mongo:9.0) with Docker. Replace 203.0.113.20 with the server's IP. Because the --rm option is added, the container is deleted automatically when the command finishes. -it is an option that attaches a terminal so that you can enter the password.

docker run --rm -it mongo:9.0 mongosh "mongodb://203.0.113.20:27017/appdb" -u appuser -p --quiet --eval "db.items.find()"
Enter password: ********************
[ { _id: ObjectId('6adef865f828b34bda0b8877'), name: 'hello' } ]

If the data you stored in step 7 is displayed, remote access is working. Also check that commands are refused when you connect without a user.

docker run --rm -it mongo:9.0 mongosh "mongodb://203.0.113.20:27017/appdb" --quiet --eval "db.items.find()"
MongoServerError: Command find requires authentication

11. Troubleshooting

MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

This means that you connected from inside the server, but MongoDB is not running. The service does not start right after installation. Check the status with sudo systemctl status mongod --no-pager and start it with sudo systemctl start mongod.

MongoNetworkError: connect ECONNREFUSED 203.0.113.20:27017

This means that you connected from your PC and the server refused the connection. This error occurs in two cases. The first is when there is no firewalld rule. firewalld on RHEL 10 rejects connections to ports that are not allowed, so this error is displayed instead of a timeout. Check the rules with sudo firewall-cmd --list-rich-rules. The second is when bindIp is 127.0.0.1. Check it with grep -n -A2 "^net:" /etc/mongod.conf.

MongoServerError: Command listDatabases requires authentication

This means that you ran a command without a user after turning on authentication. Connect with -u admin -p --authenticationDatabase admin (admin) or "mongodb://localhost:27017/appdb" -u appuser -p (dedicated user).

MongoServerError: Authentication failed.

This means that the user name, the password or the authentication database is wrong. admin authenticates against the admin database, and appuser against the appdb database.

MongoServerError: not authorized on otherdb to execute command …

This means that you used a database on which appuser has no permissions. This guide allows only reading and writing (readWrite) on appdb. If you need to use other databases as well, connect as the admin user and add permissions on that database to appuser.

12. Uninstall

First, delete the port 27017 rule you added to the firewall.

sudo firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="203.0.113.10/32" port port="27017" protocol="tcp" accept'
sudo firewall-cmd --reload
success
success

Stop MongoDB and delete the packages. Because this also deletes the data stored in /var/lib/mongo, back up any data you need first.

sudo systemctl stop mongod

When you delete the packages that start with mongodb-org, mongosh and the backup tools that were installed with them are also deleted as packages that are no longer used.

sudo dnf remove -y "mongodb-org*"
Removing:
 mongodb-org                      x86_64 9.0.4-1.el10    @mongodb-org-9.0   0
 mongodb-org-database             x86_64 9.0.4-1.el10    @mongodb-org-9.0   0
 mongodb-org-database-tools-extra x86_64 9.0.4-1.el10    @mongodb-org-9.0  15 k
 mongodb-org-mongos               x86_64 9.0.4-1.el10    @mongodb-org-9.0 211 M
 mongodb-org-server               x86_64 9.0.4-1.el10    @mongodb-org-9.0 290 M
 mongodb-org-tools                x86_64 9.0.4-1.el10    @mongodb-org-9.0   0
Removing unused dependencies:
 mongodb-database-tools           x86_64 100.19.1-1      @mongodb-org-9.0 122 M
 mongodb-mongosh                  x86_64 2.14.0-1.el8    @mongodb-org-9.0 279 M

…
Complete!

Delete the data and log folders, and the repository configuration file you created in step 2.

sudo rm -rf /var/log/mongodb /var/lib/mongo
sudo rm /etc/yum.repos.d/mongodb-org-9.0.repo

Check that no MongoDB packages remain. If 0 is displayed, everything has been deleted.

rpm -qa | grep -c mongo
0