Analyze. Act. Achieve.
Kurinchilion KURINCHILION Analyze. Act. Achieve.

News

How to create SSH tunnel and connect to the remote mongo database via command line?

Command to establish the SSH Tunnel to MongoDB on remote server

$ ssh -L :27018:127.0.0.1:27017 -i /path/serverkey.pem remoteserverUSER@remoteserverIP -N -v -v

Command description

/path/serverkey.pem - certificate file to access the remoteserver

remoteserverUSER - user name to access the remote server

remoteserverIP - remote server host IP address (where mongod runs)

127.0.0.1:27017 - local IP address and port on the remote server

27018 - port number that connects local machine to remote

Once the connection is established to the remote server, you can connect to MongoDB via Compass or through the Mongo CLI.