
Secure your Apache web server on RHEL 9 or CentOS Stream 9 with a hardened TLS configuration. Learn how to enable TLS 1.2/1.3, enforce strong
Learn how to secure MongoDB on RHEL 9 using TLS / SSL—step-by-step instructions for certificate setup, configuring mongod, enforcing client authentication, and troubleshooting.
Transport Layer Security (TLS) / SSL is essential to protect MongoDB traffic from eavesdropping and man-in-the-middle attacks. In this guide, you’ll learn how to enable TLS for mongod or mongos on RHEL 9, using both server certificates and optional client certificate validation.
✅ Why Use TLS / SSL for MongoDB? |
|
|
|
|
|
💡NOTE: MongoDB’s TLS support is built on the system OpenSSL library. |
This tutorial assumes you already have a working MongoDB installation on RHEL 9, and basic knowledge of TLS / PKI.
You need at least:
|
|
|
Here’s a minimal example using OpenSSL (for testing/dev). In production, use a proper CA or trusted provider.
# Create CA private key and self-signed certificate
openssl genpkey -algorithm RSA -out ca.key -pkeyopt rsa_keygen_bits:4096
openssl req -x509 -new -nodes -key ca.key -sha256 -days 3650 \
-subj "/C=US/ST=State/L=City/O=Org/OU=IT/CN=MyCA" \
-out ca.pem
# Create server key and CSR
openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -key server.key -subj "/C=US/ST=State/L=City/O=Org/OU=DB/CN=db.example.com" -out server.csr
# Sign server CSR with CA
openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial \
-out server.crt -days 365 -sha256
# Combine server key + cert into a PEM file MongoDB can consume
cat server.key server.crt > mongodb.pem
# (Optional) Create client cert + key
openssl genpkey -algorithm RSA -out client.key -pkeyopt rsa_keygen_bits:2048
openssl req -new -key client.key -subj "/C=US/ST=State/L=City/O=Org/OU=Client/CN=client1" \
-out client.csr
openssl x509 -req -in client.csr -CA ca.pem -CAkey ca.key -CAcreateserial \
-out client.crt -days 365 -sha256
cat client.key client.crt > client.pem
🟢 Key points |
|
|
|
All PEM files should have secure file permissions (e.g. 600) and reside in a protected directory (e.g. /etc/ssl/mongo/).
mongod / mongos to Use TLSOn RHEL 9, the MongoDB package uses the mongod.conf configuration file. You can also pass flags manually, but config is more maintainable.
Here’s an example addition to /etc/mongod.conf:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongo/mongodb.pem
CAFile: /etc/ssl/mongo/ca.pem
# disabledProtocols: TLS1_0,TLS1_1 # optional
# CRLFile: /etc/ssl/mongo/crl.pem # optional
security:
# optional: enforce client certs (X.509)
# but this must be consistent across replica set / cluster
authorization: enabled
# For internal cluster (replica sets / shards) auth:
# clusterAuthMode: x509
| Setting | Description |
mode: requireTLS | Forces all connections to use TLS (no plaintext) |
certificateKeyFile | Path to server’s certificate + key |
CAFile | Certificate(s) to validate client certs |
disabledProtocols | Disable weak protocols (e.g. TLS1.0 / 1.1) |
CRLFile | Certificate Revocation List, for blocked certs |
If you prefer command-line flags, the equivalents are:
mongod --tlsMode requireTLS \
--tlsCertificateKeyFile /etc/ssl/mongo/mongodb.pem \
--tlsCAFile /etc/ssl/mongo/ca.pem
Once configured, restart MongoDB:
sudo systemctl restart mongod
sudo journalctl -u mongod -f
Watch the logs for any TLS handshake or certificate errors.
If you require clients to present valid certificates, enable X.509 client authentication:
net:
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongo/mongodb.pem
CAFile: /etc/ssl/mongo/ca.pem
allowConnectionsWithoutCertificates: false
security:
clusterAuthMode: x509
|
|
|
On the client side, connect like:
mongosh --tls --host db.example.com:27017 \
--tlsCAFile /etc/ssl/mongo/ca.pem \
--tlsCertificateKeyFile /etc/ssl/mongo/client.pem \
-u "CN=client1,OU=Client,O=Org,..." --authenticationMechanism MONGODB-X509
If you use multiple clients, issue distinct client certificates per user to allow selective revocation.
Assuming server is listening on db.example.com:27017:
# Simple client (no client certificate)
mongosh --tls --host db.example.com:27017 \
--tlsCAFile /etc/ssl/mongo/ca.pem
# With client cert + authentication
mongosh --tls --host db.example.com:27017 \
--tlsCAFile /etc/ssl/mongo/ca.pem \
--tlsCertificateKeyFile /path/to/client.pem \
--authenticationMechanism MONGODB-X509 \
-u "CN=client1,OU=Client,O=Org,C=US"
If you get a self signed certificate or Hostname/IP does not match certificate’s altnames error, you can—for testing—add:
|
|
But never use these in production.
💡As many users on forums report, connection failures are often due to missing |
🟢 Disable Weak Protocols & Ciphers |
You can disallow TLS 1.0 and 1.1 negotiation:
net:
tls:
disabledProtocols: TLS1_0,TLS1_1
As of MongoDB’s documentation, only strong ciphers (≥ 128 bits) are permitted by default.
🟢 Enable Online Certificate Rotation |
MongoDB 5.0 and later supports online rotation of TLS / CA files without downtime. Confirm your version supports that if needed.
🟢 Monitor Logs |
Check for handshake failures, certificate expiry warnings (Mongo logs warn if within 30 days).
🟢 Example TLS-Related Log Entries |
2025-10-11T10:22:33.123+0000 I NETWORK [connX] connection accepted from 203.0.113.5:56742 #Y (1 connection now open)
2025-10-11T10:22:33.124+0000 E NETWORK [connX] SSLHandshakeFailed: SSL peer certificate validation failed
| Symptom | Likely Cause | Solution |
|---|---|---|
| “self signed certificate” | Client does not trust CA | Use correct --tlsCAFile, do not bypass trust in production |
| Hostname mismatch | CN / SAN doesn’t match connection host | Regenerate server cert with correct SANs |
| “isMaster” network error or handshake failure | Missing TLS flags or misconfig | Add --tlsCertificateKeyFile and --tlsCAFile to client |
| Connection success via IP but failure via DNS | DNS name not in SAN | Include both IP and DNS in SAN when generating cert |
| Expired certificate warnings | Cert near expiration | Rotate certs (or use online rotation) |
Also, avoid redundancy between net.tls and net.ssl—MongoDB accepts either alias, but tls is preferred in recent versions.
mongod.conf (RHEL 9)
# mongod.conf
storage:
dbPath: /var/lib/mongo
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
processManagement:
fork: false # if using systemd
net:
port: 27017
bindIp: 0.0.0.0
tls:
mode: requireTLS
certificateKeyFile: /etc/ssl/mongo/mongodb.pem
CAFile: /etc/ssl/mongo/ca.pem
disabledProtocols: TLS1_0,TLS1_1
security:
authorization: enabled
# Optional (if using x509)
# clusterAuthMode: x509
Ensure file permissions:
chown mongod:mongod /etc/ssl/mongo/*.pem
chmod 600 /etc/ssl/mongo/*.pem
Restart and monitor:
sudo systemctl restart mongod
sudo tail -F /var/log/mongodb/mongod.log
Securing MongoDB with TLS on RHEL 9 is a critical step toward ensuring the confidentiality and integrity of your database communications. Whether you’re operating a single instance or a complex replica set, enabling TLS/SSL protects data in transit from interception and tampering.
In this guide, we walked through the process of generating trusted certificates, configuring |
By disabling outdated protocols, enforcing strict certificate validation, and regularly rotating credentials, you build a hardened MongoDB environment that aligns with modern security standards and compliance requirements.
With MongoDB properly secured over TLS, you can confidently scale your deployment knowing that your data is protected at every network boundary. Take time to automate certificate renewal and review your security posture periodically to stay ahead of evolving threats. |
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.

Secure your Apache web server on RHEL 9 or CentOS Stream 9 with a hardened TLS configuration. Learn how to enable TLS 1.2/1.3, enforce strong

Learn how to configure etcd with SSL/TLS on RHEL 8 or CentOS 8 for secure communication. This step-by-step guide covers everything from generating certificates to

In this article, we’ll explore the simple steps to enable HTTPS on your website. We’ll guide you through the process of installing SSL on RHEL9,
