In magento 2: How can I see the user who is currently logged in from php? and How can I login to a user from code and save it in the database?
Magento provides info about the users currently online under customer section itself.
If you need to get the list of customers currently online you can make use of values from two magento database tables as per your need,
These table have a sessions of customers
You can login as a user by using a plugin https://github.com/magefan/module-login-as-customer