I want to access a remote mongodb with SSH tunnel, but booster always tries to connect to localhost?

吳丹紅 shared this question 5 years ago
Answered

I want to access a remote mongodb with SSH tunnel, I did "Test Connection", connection to SSH tunnel is OK, but then NoSQLBooster always tries to connect to localhost, like localhost:39707 or any other ports, while by the configuration it should connect to a remote host with port 27017 which I configured, what is wrong?


14:57:32.248  *** Starting "Connect to SSH Server" ***
{"askForPassword":false,"authMode":2,"keyPath":"/Users/kitty/id_rsa","passphrase":"","port":24822,"server":"51.222.144.114","username":"sysop"} 

14:57:32.485  *** Finished "Connect to SSH Server" 237 ms***
{"askForPassword":false,"authMode":2,"keyPath":"/Users/kitty/id_rsa","passphrase":"","port":24822,"server":"51.222.144.114","username":"sysop"} 

14:57:32.486  *** Starting MongoClient.connect ***
{"options":{"appname":"NoSQLBoosterV5_145315.759","autoReconnect":true,"keepAlive":60000,"minSize":0,"poolSize":0,"promoteLongs":false,"promoteValues":false,"reconnectTries":172800,"socketTimeoutMS":0,"sslValidate":false,"useNewUrlParser":false},"uri":"mongodb://root:t4aAlxffgM7A8@localhost:39707/alita?authSource=alita"} 

14:57:33.521  *** Connect Error ***
{"errorLabels":["TransientTransactionError"],"message":"connection 6 to localhost:39707 closed","name":"MongoNetworkError","stack":"MongoNetworkError: connection 6 to localhost:39707 closed\n    at Socket.<anonymous> (/Applications/NoSQLBooster for MongoDB.app/Contents/Resources/app.asar/node_modules/mongodb-core/lib/connection/connection.js:276:9)\n    at Object.onceWrapper (events.js:273:13)\n    at Socket.emit (events.js:182:13)\n    at TCP._handle.close [as _onclose] (net.js:596:12)"} 

Replies (1)

photo
1

About SSH tunnel: Local forwarding is used to forward a port(e.g. 39707 random port) from the client machine to the server machine (port:27017). Basically, the SSH client listens for connections on a configured port (e.g. 39707 random port) , and when it receives a connection, it tunnels the connection to an SSH server. The server connects to a configurated destination port (port:27017), possibly on a different machine than the SSH server


1. Why Random port?

A: We use random unoccupied ports (_.random(30000, 60000)) to avoid conflicts with local services

Do you have the same problem with an external SSH tunnel? refer to : https://www.ssh.com/ssh/tunneling/example#sec-What-Is-SSH-Port-Forwarding-aka-SSH-Tunneling

photo
1

you mean the ssh client listen on a port, in this case it is 39707? are you sure? I think it is that the local client use localhost: a-random-port to establish a tcp connection with ssh server and ssh server establishes a connection with destination:27017, isn't it?

and it seems to me that my client has established a connection with destination:27017, isn't it?

photo
1

I mean that the ssh client listens on a random port (30000-60000) and forward to the remote server server_address:27017. The port 39707 is just a used sample port.

Did you try the external SSH tunnel? The reason I asked you to check the external SSH Tunnel command or other MongoDB tools (e.g. MongoDB Compass) was that I wanted to make sure that the SSH tunnel itself worked and that there was no problem with the server connection

photo
1

Is this solved? I am also facing similar issues.

photo
1

I also have the same problem, i want the port number to be fixed rather than taking it dynamically, can we do that?

photo
1

I solved.

This is not port issue.

This is id_rsa key file format issue.

Check your id_rsa key file format.

It will probably start not with "-----BEGIN RSA PRIVATE KEY-----".

This is RFC4716 format and not supported.

$ ssh-keygen -f id_rsa -m PEM -p

and retry.

I'm successed.

Good luck.

photo
Leave a Comment
 
Attach a file