- First, let us generate a self-signed certificate using OpenSSL, in the /data directory:
openssl req -x509 -newkey rsa:4096 -nodes -keyout mongo-secure.key -out mongo-secure.crt -days 365
- Combine the key and certificate into a single .pem file:
cat mongo-secure.key mongo-secure.crt > mongo-secure.pem
- Start the mongod daemon, with SSL enabled and listening on the default socket that is, localhost 27017:
mongod --dbpath /data/db --sslMode requireSSL --sslPEMKeyFile /data/mongo-secure.pem
- In another window, connect to this server using a mongo client:
mongo localhost:27017
- You should see a connect failed error on the client Terminal. Switch to the server's console window and you should see a log message indicating that ...