我有这个功能,当我传递正确的用户名和密码时,以及当我故意传递错误的密码时,我卡在Password:
提示符下。Net :: SSH卡住了密码提示
def perform(sensor_params)
@hostname = "10.0.10.100"
@username = "root"
@password = "root"
@cmd = "id"
begin
ssh = Net::SSH.start(@hostname, @username, :password => @password)
res = ssh.exec!(@cmd)
ssh.close
puts res
rescue
puts "Unable to connect to #{@hostname} using #{@username}/#{@password}"
end
end
任何想法,当我传递的密码不正确时,只能吐出消息“无法连接”?
感谢
缺少密码命令的双引号。 –
不知道你的目标是“我怎么只是吐出信息”。使用'non_interactive'设置并移除'rescue'块(或缩小它),该方法应该引发'Net :: SSH :: AuthenticationFailed'异常。 –