1

I am trying to use pymongo to connect to a mongo database.

I have been given: DB_name DB_username DB_password DB_port SSH_address SSH_username mongo RSA private key (.pem file)

I have tried running

from pymongo import MongoClient

client = MongoClient(host=SSH_address,
                     port=DB_port,
                     username=DB_username,
                     password=DB_password)

client.list_database_names()

but get a timed out error.

How can I pass the remaining information (such as the RSA private key) to MongoClient, so that I can successfully connect?

2
  • 1
    You need to use a ssh tunnel service of some sort. heres an example. Commented May 15, 2019 at 11:23
  • Thank you. In the end, what made it work creating a folder ~/.ssh and adding in the .pem file Commented Jun 5, 2019 at 13:56

1 Answer 1

1

Using SSH tunnel client to connect the MongoDB client works for me:

server = SSHTunnelForwarder(
    (MONGO_HOST, MONGO_PORT),
    ssh_username=MONGO_USER,
    ssh_password=MONGO_PASS,
    remote_bind_address=('127.0.0.1', 27017)
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.