【问题标题】:Ruby net-ssh wirth proxy command causes freeze带有 proxycommand 的 Ruby net-ssh 导致冻结
【发布时间】:2014-06-30 18:40:09
【问题描述】:

我想通过另一台使用 ruby​​ 连接到远程计算机。

这个方案如下:

本地 -> 代理 -> 远程

我有这段代码可以直接访问:

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

但是,当我尝试使用代理时,命令“主机名”被执行并正确,但随后代码冻结,如果我调用 ssh.close。

代码如下:

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

多亏了 rsa 密钥,登录无需密码即可完成。并且代理命令正在工作(我之前在 bash 中使用过)

有人知道我做错了什么吗?

非常感谢您的关注,

编辑:这是日志中的最后一行,它在那里阻塞:

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

【问题讨论】:

    标签: ruby-on-rails ruby ssh net-ssh


    【解决方案1】:

    我刚刚遇到了同样的问题 - 使用 proxycommand 时,命令行 ssh 正在工作,而 net/ssh 挂在我身上。

    调试 net/ssh 把我带到了:https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/transport/session.rb#L113,整个事情都挂在套接字的 .close 调用上。

    我不确定是什么原因造成的,但是在 nc 命令中添加超时似乎已经解决了:

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

    【讨论】:

    • 你有没有找到一种不那么老套的方法来解决这个问题?
    • 棘手的解决方案因为并非所有ncs 都是平等的。我的 ubuntu VM 有这个标志,而我的 fedora27 没有。并且让我们不要开始使用嵌入式(busybox)
    • 另外 - 你在 github 上的代码链接应该是更永久的东西,比如特定的哈希 - 一年后第 113 行不太可能是同样的东西
    猜你喜欢
    • 2016-11-17
    • 2013-06-11
    • 1970-01-01
    • 2012-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    相关资源
    最近更新 更多