Skip to content

Instantly share code, notes, and snippets.

@bradfordcp
Created August 24, 2011 07:58
Show Gist options
  • Save bradfordcp/1167529 to your computer and use it in GitHub Desktop.
Save bradfordcp/1167529 to your computer and use it in GitHub Desktop.
Setting up an SSH tunnel with Net::SSH::Gateway then working through that tunnel
require 'net/ssh'
require 'net/ssh/gateway'
# Connect to the gateway machine
gateway = Net::SSH::Gateway.new('host.to.tunnel.from', 'user.name')
# Open the tunnel (in this example we are using port 5900 locally)
gateway.open('host.to.tunnel.to', 22, 5900)
# SSH through our tunnel and grab the list of vault contents
Net::SSH.start('127.0.0.1', 'user.name', :port => 5900) do |ssh|
some_files = ssh.exec!('cd /data; ls')
end
# Close the tunnel
gateway.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment