One thumb up for @Nikhil Katre's answer :
Simplest command to get the last 10 users logged in to the machine is
last|head
.To get all the users simply use
last
command
The one using who
or pinky
did what is basically asked. But But But they don't give historical sessions info.
Which might also be interesting if you want to know someone who has just logged in and logged out already when you start this checking.
if it is a multiuser system. I recommand add the user account you are looking for:
last | grep $USER | head
EDIT:
In my case, both $SSH_CLIENT and $SSH_CONNECTION do not exist.