【问题标题】:How to open an SSH session in an SSH session with Net::SSH?如何使用 Net::SSH 在 SSH 会话中打开 SSH 会话?
【发布时间】:2014-08-19 18:07:49
【问题描述】:

我需要通过公共 nat 服务器 SSH 到位于私有子网中的 database 服务器。只有nat 具有允许连接到database 的RSA 密钥。我将如何使用Net::SSH 来做到这一点?

我尝试了以下方法:

def ssh
  Net::SSH.start(DB_SERVER_IP, DB_SERVER_USERNAME, proxy: proxy)
end

def proxy
  Net::SSH::Proxy::Command.new("ssh -l #{NAT_USER} -e none #{NAT_IP} exec nc %h %p 2>/dev/null")        
end

这种方法确实使私有database 服务器对localhost 可见,但localhost 没有 RSA 密钥来连接它,并且连接失败

Permission denied (publickey). 

【问题讨论】:

    标签: ruby ssh tunnel


    【解决方案1】:

    解决方法:

    def ssh
      Net::SSH.start(DB_SERVER_IP, DB_SERVER_USERNAME, proxy: proxy, key_data: [pem])
    end
    
    def proxy
      Net::SSH::Proxy::Command.new("ssh -l #{NAT_USER} -e none #{NAT_IP} exec nc %h %p 2>/dev/null")        
    end
    
    def pem
      Net::SSH.start(NAT_IP, NAT_USER).exec!('cat ~/.ssh/the.pem')
    end
    

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多