Skip to content

Instantly share code, notes, and snippets.

@umidjons
Last active December 12, 2022 07:24
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save umidjons/ec7a60415c452787f2666ef6761bbf69 to your computer and use it in GitHub Desktop.
Save umidjons/ec7a60415c452787f2666ef6761bbf69 to your computer and use it in GitHub Desktop.
Create ssh tunnel and connect to the remote mongo database on command line

Create ssh tunnel and connect to the remote mongo database on command line

Assume followings:

/mykeys/.ssh/prodserver.pem - is a certificate file

umid - is a user name

111.111.111.111 - is a remote host, that mongodb runs

2222 - is a remote port to connect via ssh

localhost:27017 - local host and port on remote machine

27018 - local port

ssh -i /mykeys/.ssh/prodserver.pem umid@111.111.111.111 -p 2222 -Nf -L 27018:localhost:27017

Connect to the mongodb via opened tunnel, in this case mydb is database name

mongo --port 27018 mydb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment