Skip to content

Instantly share code, notes, and snippets.

@dandorman
Created April 21, 2011 14:57
Show Gist options
  • Save dandorman/934697 to your computer and use it in GitHub Desktop.
Save dandorman/934697 to your computer and use it in GitHub Desktop.
SSH Tunneling in Ruby by John Nunemaker
# 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