Skip to content

Instantly share code, notes, and snippets.

@mnebuerquo
Last active January 4, 2018 20:27
Show Gist options
  • Save mnebuerquo/057be354026d54a601a1d724104237aa to your computer and use it in GitHub Desktop.
Save mnebuerquo/057be354026d54a601a1d724104237aa to your computer and use it in GitHub Desktop.
Open an ssh tunnel to a mongo server through another host, so that the mongo ports are available on localhost.
#!/bin/sh
# mongodb is in a private network somewhere, host is a machine which can connect
# after running this script, you can connect to mongo at localhost
MONGO=$1
HOST=$2
ssh -fnN \
-L 27017:$MONGO:27017 \
-L 27018:$MONGO:27018 \
-L 27019:$MONGO:27019 \
$HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment