Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment