Guest User

Untitled

a guest
Nov 28th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'net/ssh'
  4. require 'yaml'
  5.  
  6. =begin
  7. To make this work just add "GatewayPorts yes" to /etc/sshd_config in your server
  8. Also, make sure that config['remote_port'] is open in your server.
  9.  
  10. the config file (config/tunnel.yml) looks like this:
  11.  
  12. username: tunnlr3442
  13. host: ssh1.tunnlr.com
  14. password: my-password
  15. remote_port: 12785
  16. local_port: 3000
  17.  
  18. =end
  19.  
  20.  
  21.  
  22. config = YAML.load_file('./config/tunnel.yml')
  23.  
  24. begin
  25. ssh = Net::SSH::start(config['host'], config['username'], :password => config['password'])
  26. ssh.forward.remote_to(config['local_port'], '127.0.0.1', config['remote_port'], '0.0.0.0')
  27.  
  28. puts "Started!"
  29. ssh.loop { true }
  30. rescue Errno::ECONNREFUSED
  31. puts "Please start the web server"
  32. retry
  33. rescue Net::SSH::Exception
  34. retry # retry if the connection is lost
  35. end
Add Comment
Please, Sign In to add comment