Created
April 21, 2011 14:57
-
-
Save dandorman/934697 to your computer and use it in GitHub Desktop.
SSH Tunneling in Ruby by John Nunemaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://railstips.org/blog/archives/2011/04/19/ssh-tunneling-in-ruby/ | |
require 'net/ssh/gateway' | |
gateway = Net::SSH::Gateway.new('<myremotehostorip.com>', '<remote_user>') | |
# Open port 27018 to forward to 127.0.0.1:27017 | |
# on the remote host provided above | |
gateway.open('127.0.0.1', 27017, 27018) | |
# Connect to local port set in previous statement | |
conn = Mongo::Connection.new('127.0.0.1', 27018) | |
# Just printing out stats to show that it works | |
puts conn.db('<database_name>').stats.inspect | |
gateway.shutdown! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment