Created
July 28, 2012 23:30
-
-
Save dcu/3195258 to your computer and use it in GitHub Desktop.
ssh reverse tunneling for rails/padrino
This file contains hidden or 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
#!/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