Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techntools/ab9f72ca96d87253a8a406450fd81665 to your computer and use it in GitHub Desktop.
Save techntools/ab9f72ca96d87253a8a406450fd81665 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