【问题标题】:Ruby/NetSSH try username and password only once?Ruby/Net SSH 只尝试一次用户名和密码?
【发布时间】:2015-01-15 08:04:34
【问题描述】:

有没有办法在使用Net::SSH.start() 尝试用户名和密码序列后立即失败?我正在测试以查看凭据是否有效然后停止,这是我拥有的代码

output = 0
Net::SSH.start('host', 'user', :password => "pass") do |ssh|
   output = ssh.exec! 'echo "1"'
end
puts output

【问题讨论】:

    标签: ruby net-ssh


    【解决方案1】:

    这应该将身份验证限制为仅password,并且没有提示或重试:

    Net::SSH.start('host', 'user',  
                   :password     => 'pass', 
                   :auth_methods => [ 'password' ],
                   :number_of_password_prompts => 0)
    

    :auth_methods 将 SSH 限制为仅尝试数组中列出的那些身份验证方法。在这种情况下,我们只想尝试密码验证。

    :number_of_password_prompts 仅适用于password auth 方法,如果将其设置为零,即使身份验证失败,它也不会提示输入密码。

    【讨论】:

    • 我在文档中的任何地方都找不到这个,现在我突然想到这是一个ssh-config 选项,谢谢!
    猜你喜欢
    • 2023-03-27
    • 2018-04-22
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-19
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    相关资源
    最近更新 更多