是否有办法在使用 Net::SSH.start()
尝试输入用户名和密码序列后立即失败?我想测试一下凭据是否有效,然后停止,这是我的代码
output = 0
Net::SSH.start('host', 'user', :password => "pass") do |ssh|
output = ssh.exec! 'echo "1"'
end
puts output
最佳答案
这应该将身份验证限制为仅密码
,并且没有提示或重试:
Net::SSH.start('host', 'user',
:password => 'pass',
:auth_methods => [ 'password' ],
:number_of_password_prompts => 0)
:auth_methods
限制 SSH 仅尝试数组中列出的身份验证方法。在本例中,我们只想尝试密码身份验证。
:number_of_password_prompts
仅适用于 password
身份验证方法,如果将其设置为零,它将永远不会提示输入密码,即使如果认证失败。
关于Ruby/Net SSH 只尝试一次用户名和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27954274/