Skip to content

Instantly share code, notes, and snippets.

Created July 12, 2013 10:17
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#! /usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require "net/ssh/gateway"
# Terminal equivalent
# #ssh -R0.0.0.0:9999:localhost:3000
puts "Enter the remote server name you wish to forward your local port to: ("
remote_host = gets.chomp
puts "Enter the remote port you wish your local app to be available on - on the remote server (ex: 9999)"
remote_port = gets.chomp
puts "Enter remote server user to ssh with"
remote_user = gets.chomp
puts "Enter local port to forward"
local_port = gets.chomp
remote_host = "" if remote_host.empty? || remote_host.nil?
remote_port = 9999 if remote_port.empty? || remote_port.nil?
remote_user = "sid" if remote_user.empty? || remote_user.nil?
local_port = 3000 if local_port.empty? || local_port.nil?
gateway =, remote_user)
puts "Forwarding{local_port} to #{remote_host}:#{remote_port}"
#remote_host = ""
Net::SSH.start(remote_host, remote_user) do |ssh|
puts "Connecting..."
#puts ssh.inspect
ssh.logger.sev_threshold = Logger::Severity::DEBUG
#remote forward from remote to established
ssh.forward.remote(local_port, '', remote_port, remote_host)
ssh.loop { true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment