Ruby net-ssh-gateway 总是报错 Net::SSH::AuthenticationFailed

linus · July 19, 2013 · Last by linus replied at July 19, 2013 · 2967 hits
all_machines=['192.168.0.100']
gateway = Net::SSH::Gateway.new('192.168.0.1', 'root', :password => 'root')
all_machines.each do |machine|
  gateway.ssh(machine,'root') do |ssh|
    uname = ssh.exec!('uname -a')
    puts "machine: #{machine}; OS: #{uname}"
  end
end

我是在比较让人灰心的 windows7 上,因为本来就是想用作通过网关登陆节点机器。在 Linux 上是工作正常的

出错的地方就是在 127.0.0.1 上,我要是都写成 password 登陆是没有问题的。关键是网关服务器和节点机器是公钥验证的。

def ssh(host, user, options={}, &block)
  local_port = open(host, options[:port] || 22)

  begin
   Net::SSH.start("127.0.0.1", user, options.merge(:port => local_port), &block)

  ensure
    close(local_port) if block || $!
  end
end

private

像这种写法也试过。我现在不知道哪个地方有错了。

Net::SSH.start(
  'host', 'user',
  :host_key => "ssh-rsa",
  :encryption => "blowfish-cbc",
  :keys => [ "/tmp/temporary-key" ],
  :compression => "zlib"
) do |session|
  ...
end
You need to Sign in before reply, if you don't have an account, please Sign up first.