2

Is there a way to fail immediately after trying a username and password sequence with Net::SSH.start()? I am looking to test to see if credentials work then stop afterwards, here is the code that I have

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

1 Answer 1

4

This should restrict authentication to password only, and no prompts or retries:

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

:auth_methods restricts SSH to only try those authentication methods which are listed in the array. In this case we only want to try password authentication.

:number_of_password_prompts only works with the password auth method, and if you set it to zero it will never prompt for a password, even if the authentication fails.

Sign up to request clarification or add additional context in comments.

1 Comment

I couldn't find this anywhere in the docs, and it occurs to me now that this is a ssh-config option, thank you for this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.