因此,這裏是我的設置:多個SSH與淨啤酒花:: SSH(紅寶石)
筆記本電腦 - >主機1 - >主機2 - >主機3
筆記本可以達到主機1臺,但不是主機2或主機3
主機1可以達到主機2,而不是主機3
主機3可以達到主機2,而不是主機1
我試圖做的是建立遠程前鋒,這樣運行的進程在主機3上將被路由到在筆記本電腦上運行服務。從主機
require 'rubygems'
require 'net/ssh'
threads = []
config = {:user => "user", :remote_port => 3333, :service_port => 2222}
threads << Thread.new{
Net::SSH.start("host1", config[:user]) do |ssh|
puts "Forwarding port #{config[:remote_port]} on host1 to #{config[:service_port]} on localhost"
ssh.forward.remote(config[:service_port], "localhost", config[:remote_port], "127.0.0.1")
ssh.exec! "ssh #{config[:user]}@host2 -R #{config[:remote_port]}:localhost:#{config[:remote_port]}"
ssh.loop {true}
end
}
threads << Thread.new{
Net::SSH.start("host3", config[:user]) do |ssh|
puts "Creating local forward for port #{config[:service_port]} on host3 to port #{config[:remote_port]} on host2"
ssh.exec! "ssh #{config[:user]}@host2 -L #{config[:service_port]}:localhost:#{config[:remote_port]}"
ssh.loop {true}
end
}
threads.each {|t| t.join}
在一個線程中,我從筆記本電腦設置遠程着主機1臺,然後又遙控前進:我已經成功地做到了這一點使用下面的代碼:
從筆記本電腦上運行1到主機2。在一個單獨的線程,我開始從筆記本電腦的另一個連接到主機3,然後運行從主機3當地提出承辦2.
我可以從筆記本電腦連接到主機3的唯一方法是因爲我的.ssh/config文件,它會自動路由我通過主機1和主機2,當我嘗試連接到筆記本電腦,從主機3。
我想要做的是切出在那裏我從筆記本電腦連接到主機3,這樣我可以去除你的.ssh/config文件的依賴第二個線程。我想在第一個線程中完成所有的連接。
所以基本上我需要做的多跳,從筆記本電腦起源。我可以啓動從筆記本電腦到主機1的第一個連接,然後在主機1上執行一個命令,但之後我無法再進一步了。我需要做的是啓動從筆記本電腦到主機1的連接,在主機1上建立轉發,從主機1連接到主機2,然後在主機2上設置第二個轉發。
這是可能的與淨/ SSH?
感謝您的幫助!