Guest User

Untitled

a guest
Apr 13th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def connect
  2. if @ssh.nil?
  3. # @password => {:password=>"..."} if a password is provided, otherwise => {}
  4. options = @password.merge({
  5. :timeout=>2,
  6. # :auth_methods => %w(publickey hostbased password, keyboard-interactive)
  7. :auth_methods => %w(publickey hostbased password)
  8. })
  9. options = @password.merge({:verbose=>Logger::DEBUG}) if @choices[:ssh_debug]
  10. @logger.debug { "connect: @machine=>#{@machine}, @user=>#{@user}, options=>#{options.inspect}" }
  11. begin
  12. @ssh = Net::SSH.start(@machine, @user, options)
  13. # @ssh.forward.local(@port, @machine, @port)
  14. rescue Net::SSH::AuthenticationFailed
  15. @logger.error { "connect raised Net::SSH::AuthenticationFailed" }
  16. @ssh = nil
  17. raise Net::SSH::AuthenticationFailed.new(@name)
  18. rescue Exception => e
  19. @logger.error { "connect raised #{e}"}
  20. @ssh = nil
  21. raise e
  22. end
  23. end
  24. end
Add Comment
Please, Sign In to add comment