使用Net::SSH.start()
尝试用户名和密码序列后,有没有办法立即失败?我希望测试看看凭据是否有效然后停止,这是我的代码
output = 0
Net::SSH.start('host', 'user', :password => "pass") do |ssh|
output = ssh.exec! 'echo "1"'
end
puts output
答案 0 :(得分:3)
这应该仅将身份验证限制为password
,并且不会提示或重试:
Net::SSH.start('host', 'user',
:password => 'pass',
:auth_methods => [ 'password' ],
:number_of_password_prompts => 0)
:auth_methods
限制SSH仅尝试数组中列出的身份验证方法。在这种情况下,我们只想尝试密码验证。
:number_of_password_prompts
仅适用于password
身份验证方法,如果将其设置为零,即使身份验证失败,也不会提示输入密码。