Skip to content

Instantly share code, notes, and snippets.

@dcu
Created July 28, 2012 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcu/3195258 to your computer and use it in GitHub Desktop.
Save dcu/3195258 to your computer and use it in GitHub Desktop.
ssh reverse tunneling for rails/padrino
#!/usr/bin/env ruby
require 'net/ssh'
require 'yaml'
=begin
To make this work just add "GatewayPorts yes" to /etc/sshd_config in your server
Also, make sure that config['remote_port'] is open in your server.
the config file (config/tunnel.yml) looks like this:
username: tunnlr3442
host: ssh1.tunnlr.com
password: my-password
remote_port: 12785
local_port: 3000
=end
config = YAML.load_file('./config/tunnel.yml')
begin
ssh = Net::SSH::start(config['host'], config['username'], :password => config['password'])
ssh.forward.remote_to(config['local_port'], '127.0.0.1', config['remote_port'], '0.0.0.0')
puts "Started!"
ssh.loop { true }
rescue Errno::ECONNREFUSED
puts "Please start the web server"
retry
rescue Net::SSH::Exception
retry # retry if the connection is lost
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment