AWS SSH tunnel fail to connect to MongoDB Atlas Cluster

Chew L.M shared this question 4 years ago
Answered

Hi,

I have the version 6.0.4 version of the app.

I am having problem connecting to MongoDB Atlas Cluster via the SSH tunnel, I keep getting the following error.

/56f6e9c0fa4508c0ce1e6308bf0b4b12


I can connect to the MongoDB Atlas Cluster when:

- I connect to it directly without SSH Tunnel from my local Ubuntu PC

- I connect to it directly via mongo from the AWS Ubuntu Server


I have created test Ubuntu AWS server and MongoDB Cluster that you can use to replicate this issue with.

Here is the Connection String used in NoSQLBooster:

mongodb+srv://tempUser:temp123@test-cluster.xqwpe.mongodb.net/test?retryWrites=true&w=majority
Here is the command to connect to the cluster from the AWS server:

./mongo "mongodb+srv://test-cluster.xqwpe.mongodb.net/test" --username tempUser
Here is command used to connect to the AWS Server:
ssh -i "temp_key.pem" ubuntu@ec2-13-48-236-196.eu-north-1.compute.amazonaws.com
Here is the content of the temp_key.pem file:

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAgLfkqfqOFs6bxiyp9QHkd9EO2CfCrus/8ct2U58MDkPIRYkD4e1ER6NFKeAr
+f5xUF0qPpQ4jzq7BY//+QFGttARqCG9dmZtb3rN4QFiq53+zjSiidkGr2g7qL0fEGC0cFTXNZ3c
FVD6nyGsSy5cH0CrlVS/4EqnxanAKNCaJsZ+NhRUhO3cdb3JYHDA8rGDBSaD7oP/hCAmZ4Gdl7yL
8qW18Ce3giPd//2PGnmQavJPmHvTMfUN1DYv/k90nrwtYFOH1nj0NsDE88jP6qKU5ET21ymAL8uV
XIbGcmh/s0cZJ8aWMKT5sYvRehIh3bHW7WglK5uK8Oqhote6VclqsQIDAQABAoIBAAv4DY04vSml
wJpm4M7lhCcYC3dSCypUubd0IeaYrXhOGTtOCExj0auPpQjFzZELdeHxJ9J12eSHo4ha4YR39+lb
46hsqr9tutNY6ff4NwKaSG1IO6zxv0tkN9fy7gaJ131yhih4K1TYGNXfPbQn9Wz6iHn0TXs/teYN
aM7ixtLAFHhxS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me know once you are done with the server and cluster, so that i can remove them. :-)

Best Regards,

Chew

Best Answer
photo

I tried your connection without SSH. It failed, please check your mongodb URI.

/ef96a98cf32bb20a427d374b069402a7


By the way, I passed the database connection test for the MongoDB M121 course over my SSH tunnel. Here is the connection URI:

mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017/aggregations?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&ext.ssh.server=example.com:22&ext.ssh.username=ubuntu&ext.ssh.keyPath=C:\Users\qinghai\.ssh\test.pem

Replies (3)

photo
1

Just in case it is due to something I set, here are how I set them in the app:


/85464cc6b82f339ce255f6d499634134

/22f5821d9a7a9240289eaefe422bb5bc

/ffbd9f2f94e4e6ec73a2084bb13b8972

/32f4dce1a786633e4a71c8ed6031d4b1

/b0169dffe5c6eec1d41691f753c6654f

/b03192a985fe619660375a0e9b386bbd

photo
1

NoSQLBooster does not support DNS Seedlist Connection (mongodb+srv:) over an ssh tunnel. Instead, you can use the standard connection string format on the ssh tunnel

(mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl)

photo
1

Hi,

I have tried your suggestion.


mongodb://tempUser:temp123@test-cluster-shard-00-00.xqwpe.mongodb.net:27017,test-cluster-shard-00-01.xqwpe.mongodb.net:27017,test-cluster-shard-00-02.xqwpe.mongodb.net:27017/?ssl=true&replicaSet=atlas-rftich-shard-0&ext.ssh.server=ec2-13-48-236-196.eu-north-1.compute.amazonaws.com:22&ext.ssh.username=root&ext.ssh.keyPath=/ec2-13-49-9-129.eu-north-1.compute.amazonaws.com/temp_key.pem

/389d881b0f5b003639bafa5a61f20cdd

But when i tried to test the connection i get this error when using with SSH Tunnel.

/6afde00e2ea807a6d253967cd322836b

The test is successful when tested with SSH Tunnel off:

/c224e552edc25e3d4078a683504b1665

photo
2

I tried your connection without SSH. It failed, please check your mongodb URI.

/ef96a98cf32bb20a427d374b069402a7


By the way, I passed the database connection test for the MongoDB M121 course over my SSH tunnel. Here is the connection URI:

mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017/aggregations?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&ext.ssh.server=example.com:22&ext.ssh.username=ubuntu&ext.ssh.keyPath=C:\Users\qinghai\.ssh\test.pem

photo
1

Thanks, I managed to get to work after modifying my connection string to look similar to yours.

mongodb://tempUser:temp123@test-cluster-shard-00-00.xqwpe.mongodb.net:27017/?ssl=true&replicaSet=atlas-rftich-shard-0&ext.ssh.server=ec2-13-48-236-196.eu-north-1.compute.amazonaws.com:22&ext.ssh.username=root&ext.ssh.keyPath=/ec2-13-49-9-129.eu-north-1.compute.amazonaws.com/temp_key.pem

photo
Leave a Comment
 
Attach a file