Menu Close

SSH forwarding MongoDB port from remote to local

techwetrust post image

How to SSH forward MongoDB’s port from the remote machine to the local machine’s port

Consider you have a MongoDB instance running on a remote server and you want to access it without exposing it to the public. You can access it by forwarding its port through an SSH connection between your PC and your remote server.


An instance of MongoDB is running on our remote server on port 21017. We will access it on localhost:21017 by SSH port forwarding.

ssh -L 27017:REMOTE_IP:27017 root@REMOTE_IP

Now, you can connect to localhost:21017 with a MongoDB client and your traffic will be forwarded to the remote machine through an SSH-opened connection.

Spread the love

Leave a Reply