Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mayeaux/a5e18949afbdb2e2d0f70a5e45f7b161 to your computer and use it in GitHub Desktop.
Save mayeaux/a5e18949afbdb2e2d0f70a5e45f7b161 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