Skip to content

Instantly share code, notes, and snippets.

@umidjons
Last active December 12, 2022 07:24
Show Gist options
  • 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 [email protected] -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