Thought it should be straight forward but I have a very hard time figuring out the following:
I got mongodb connection string: mongodb://user:[email protected]:27017/?authSource=admin
I want to be able to connect to mongo from localhost at port 1234 by doing: mongo localhost:1234
The solution is to create a tunnel, but nothing I do works for me.
I tried the following command:
ssh -L 1234:localhost:27017 user:password@123.123.123.111 -p 27017
Please help me understand what I am doing wrong.
CodePudding user response:
MongoDB and ssh use different protocols, so you can't use ssh to connect directly to a mongod process.
If you want to use an ssh tunnel you will first need to have an account on the destination machine, and use that account's credentials with ssh to connect to port 22 (assuming default port). The mongod username/password will probably not be valid for ssh.
Once the tunnel is established, you would connect to the local port using a driver or mongo shell using the connection string:
mongodb://user:[email protected]:1234/?authSource=admin
CodePudding user response:
You need to have a unix user on 123.123.123.111
ssh -L 1234:localhost:27017 UNIXuser@123.123.123.111
Then your local mongodb connection string is : mongodb://user:password@localhost:1234/?authSource=admin