簡體   English   中英

身份驗證失敗的net-ssh ruby

[英]AuthenticationFailed net-ssh ruby

當我嘗試通過Net :: SSH.start到我的debian ssh服務器並傳輸文件時,每次遇到非常奇怪的錯誤消息-'start':Net :: SSH :: AuthenticationFailed,但是所有身份驗證數據是正確的,我不知道這是什么問題。 有人遇到同樣的問題嗎? 該代碼是在ruby上編寫的,並且使用了net / ssh模塊,這是一個代碼:

require 'rubygems'
require 'net/ssh'

def copy_file(session, source_path, destination_path=nil)
  destination_path ||= source_path
  cmd = %{cat > "#{destination_path.gsub('"', '\"')}"}
  session.process.popen3(cmd) do |i, o, e|
    puts "Copying #{source_path} to #{destination_path}... "
    open(source_path) { |f| i.write(f.read) }
    puts 'Done.'
  end
end

Net::SSH.start("192.168.112.129", 
                :username=>'username',
                :password=>'password') do |session|
  copy_file(session, 'D:/test/1.txt')
  copy_file(session, '/home/timur/Documents/new_file.rb"')
end

net / ssh 2.6中沒有:username選項,您可以像設置參數一樣設置它:

Net::SSH.start('192.168.112.129', 'username', password: 'password') do |ssh|
  foo
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM