简体   繁体   English

使用带有特定端口的 ruby​​ net/ssh 打开 ssh

[英]Open ssh using ruby net/ssh with a specific port

I am trying to reflect the port as follows:我试图反映端口如下:

  Net::SSH.start( 'hostname', :username=>'', :password=>'', :port=>1234 ) do |session|      
     puts session.exec!('echo "hello"')
  end

But I am getting error: Connection refused - connect(2) for 176.71.60.78:22 (Errno::ECONNREFUSED)但我收到错误:连接被拒绝 - connect(2) for 176.71.60.78:22 (Errno::ECONNREFUSED)

So according to the "22" in error, it seems for me that the port isnt reflected... Any ideas please?所以根据错误的“22”,对我来说似乎没有反映端口......有什么想法吗?

I see docs inhttps://www.rubydoc.info/github/net-ssh/net-ssh/Net%2FSSH.start我在https://www.rubydoc.info/github/net-ssh/net-ssh/Net%2FSSH.start看到文档

.start(host, user = nil, options = {}, &block)

So所以

Net::SSH.start('hostname', '', { password: '', port: 1234 }) do |session|
  puts session.exec!('echo "hello"')
end

use it like this:像这样使用它:

Net::SSH.start( 'host', 'username',  {:password => 'password',:port => 'port'}) do |session|      
 puts session.exec!('echo "hello"')
end

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

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