Skip to content

Instantly share code, notes, and snippets.

@basgys
Created May 29, 2012 07:48
Show Gist options
  • Save basgys/2823166 to your computer and use it in GitHub Desktop.
Save basgys/2823166 to your computer and use it in GitHub Desktop.
Creates an accessible URL to your local machine via SSH
# config/tunnel.yml
public_host_username: username_ssh
public_host: my_public_domain
public_port: 8000
local_host: 0.0.0.0
local_port: 3000
# lib/tasks/tunnel.rake
namespace :tunnel do
desc "Start a ssh tunnel"
task :start => :environment do
SSH_TUNNEL = YAML.load_file("#{Rails.root}/config/tunnel.yml")
public_host_username = SSH_TUNNEL['public_host_username']
public_host = SSH_TUNNEL['public_host']
public_port = SSH_TUNNEL['public_port']
local_host = SSH_TUNNEL['local_host']
local_port = SSH_TUNNEL['local_port']
puts "Starting tunnel #{public_host}:#{public_port} \
to #{local_host}:#{local_port}"
exec "ssh -nNT -g -R *:#{public_port}:#{local_host}:#{local_port} \
#{public_host_username}@#{public_host}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment