Created
August 24, 2011 07:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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