简体   繁体   中英

Ruby net-ssh wirth proxy command causes freeze

I would like to connect to a remote computer via another using ruby.

This scheme is the following :

Local -> proxy -> remote

I have this code which is doing the work for a direct access :

require 'net/ssh'
Net::SSH.start(remote_host, remote_user) do |ssh|
    puts ssh.exec!'hostname'
end

However, when I try with the proxy, the command 'hostname' is executed and correct, but then the code freezes, same if I call ssh.close.

Here is the code :

require 'net/ssh'
require 'net/ssh/proxy/command'

proxy_cmd = Net::SSH::Proxy::Command.new('ssh proxy_user@proxy_host nc %h %p')
Net::SSH.start(remote_host, remote_user, :proxy => proxy) do |ssh|
    puts ssh.exec!'hostname'
end

The loggin is done without password thanks to a rsa key. And the proxycommand is working (I was using it in bash before)

Would someone knows what I am doing wrong ?

Thank you very much for your interest,

EDIT : here is the last line in the logs, it blocks there :

I, [2013-10-16T23:01:19.304778 #3785]  INFO -- net.ssh.connection.session[4555128]: closing remaining channels (0 open)

I've just bumped in the same issue - command line ssh was working and net/ssh was hanging on me when using proxycommand.

Debuging net/ssh brought me as far as: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/transport/session.rb#L113 and the whole thing was hanging on the .close call of the socket.

I'm not sure what caused this, but adding timeout to nc command seems to have solved it:

ProxyCommand ssh proxy_server@proxy_server nc -q 1 %h %p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM