Skip to content

Instantly share code, notes, and snippets.

@royw
Created July 17, 2009 22:02
Show Gist options
  • Save royw/149302 to your computer and use it in GitHub Desktop.
Save royw/149302 to your computer and use it in GitHub Desktop.
def connect
if @ssh.nil?
# @password => {:password=>"..."} if a password is provided, otherwise => {}
options = @password.merge({
:timeout=>2,
# :auth_methods => %w(publickey hostbased password, keyboard-interactive)
:auth_methods => %w(publickey hostbased password)
})
options = @password.merge({:verbose=>Logger::DEBUG}) if @choices[:ssh_debug]
@logger.debug { "connect: @machine=>#{@machine}, @user=>#{@user}, options=>#{options.inspect}" }
begin
@ssh = Net::SSH.start(@machine, @user, options)
# @ssh.forward.local(@port, @machine, @port)
rescue Net::SSH::AuthenticationFailed
@logger.error { "connect raised Net::SSH::AuthenticationFailed" }
@ssh = nil
raise Net::SSH::AuthenticationFailed.new(@name)
rescue Exception => e
@logger.error { "connect raised #{e}"}
@ssh = nil
raise e
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment