2015-12-28 29 views
0

错误AuthenticationFailed

/usr/local/lib/ruby/gems/1.9.1/gems/net-ssh-2.0.23/lib/net/ssh.rb:192:in 
`start': Net::SSH::AuthenticationFailed (Net::SSH::AuthenticationFailed) 

我真的不明白这是怎么回事..?我已经完成了我的研究并发现了this,但它并没有真正回答我的问题。

是否有认证失败的具体原因?我正在做的是ssh对不同的服务器,有什么具体的我需要改变?

来源:

require 'rubygems' 
require 'net/ssh' 
require 'etc' 

print "Enter password: " 
system "stty -echo" 
@password = gets.chomp 
system "stty echo" 

def logged_in(server) 
    cmd = `who`.gsub(/[ \t].*/,"").gsub(/\A.*\n/,'') 
    check = Net::SSH.start(@host, @username, :password => @password) do |ssh| 
    ssh.exec!(cmd) 
    end 
end 

@host = %w(server_names_here) do |server| 
    logged_in(server) 
end 
@username = Etc.getlogin 

我想这可能是错误的密码,所以我尝试进入以“上”,我输入正确的密码回声的密码,我也想,也许这不是拉着我的用户名所以我用:@username = 'my_username'我仍然收到同样的错误

编辑: 发现了问题,它与在@username放在做

+0

错误密码? – Jakuje

+0

@Jakuje哈哈,我刚刚编辑了关于这个细节的问题 – Bam

回答

0

问题与放置在哪里@username有关。

require 'rubygems' 
require 'net/ssh' 
require 'etc' 

print "Enter password: " 
system "stty -echo" 
@password = gets.chomp 
system "stty echo" 
@username = Etc.getlogin #<= YAY! 

def logged_in(server) 
    cmd = `who`.gsub(/[ \t].*/,"").gsub(/\A.*\n/,'') 
    check = Net::SSH.start(@host, @username, :password => @password) do |ssh| 
    ssh.exec!(cmd) 
    end 
end 

@host = %w(server_names_here) do |server| 
    logged_in(server) 
end 
相关问题