Windows:
- Download and install Putty
- Start Putty, go to Connection --> SSH --> Tunnels
Enter a "Source port". This is the port on your local machine that will be forwarded to the remote server with the MongoDB. We use 6666 here.
Enter a "Destination". This is the ip of the interface of the remote server. We assume you bound it to localhost and use the standard MongoDB port, so it is 127.0.0.1:27017 here. Don't forget to select the "IPv4" radio button. (Pic. 1)
Finally klick the "Add" button. (Pic. 2) - Now navigate to "Session" and enter the "Host Name" or IP of the remote Server with the MongoDB. (Pic. 3)
Hit the "Open" button, enter your login information and your SSH-tunnel is ready to go. - Start Mongo Management Studio and hit the blue "Connection" button. In the "Server connection" field we now enter the "local side" of the SSH-tunnel, it is 127.0.0.1:6666 (this is the "Source Port" we chose before) in our case.
Hit "Save and connect" and if all went the way it should, you are now connected to your remote database! (Pic.4)
Linux/ Mac:
- To set up a SSH-tunnel open a terminal and enter
ssh -fN -L 6666:localhost:27017 username@remote.host
where "6666" is the local "source" port (that is going to be forwarded to the remote machine), "localhost:27017" is the IP of the interface where MongoDB runs on with it's standard port, "username" is your login on the remote machine and "remote.host " its IP.
Make sure not to use low ports <1024 as "source" port, you won't be able to bind them without root privileges. You might also want to use ssh's "-i /path/to/id_rsa" parameter, if you have set up a passwordless connection based on keypairs earlier.
2. Start Mongo Management Studio and hit the blue "Connection" button. In the "Server connection" field we enter the "local side" of the SSH-tunnel, so it is 127.0.0.1:6666 (this is the "source port") in our case.
Hit "Save and connect" and if all went the way it should, you are now connected to your remote database!
Don't forget to close the SSH-tunnel after your work is done. Since the "-f"-parameter tells ssh to head the process into the background, simply find the pid of your tunnel using "ps aux |grep ssh" and kill it with "kill <pid>". This has the benefit to not kill all your other ssh connections over using "sudo killall ssh".