简体   繁体   English

Ruby net-ssh wirth proxy命令导致冻结

[英]Ruby net-ssh wirth proxy command causes freeze

I would like to connect to a remote computer via another using ruby. 我想通过另一个使用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. 但是,当我尝试使用代理时,命令'hostname'被执行并且正确,但是如果我调用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. 由于rsa密钥,登录是在没有密码的情况下完成的。 And the proxycommand is working (I was using it in bash before) 并且proxycommand正在工作(之前我在bash中使用它)

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. 我刚刚遇到了同样的问题 - 命令行ssh工作正常,net / ssh在使用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. debuging net / ssh带我到: https//github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/transport/session.rb#L113 ,整个事情都挂在了套接字的.close调用。

I'm not sure what caused this, but adding timeout to nc command seems to have solved it: 我不确定是什么导致这种情况,但是向nc命令添加超时似乎已经解决了它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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