How to see which users are logged in on OS X and Linux

There are two funky commands that can help us see who’s currently logged in, and what operations were performed last. Those two commands are who and last.

Let me show you how to use them.

The who command

Type who at the command prompt and you’ll see a list of currently logged-in users:

This system has two users logged in: versluis, via TTY, and root via PTS. We also get to see which IP addresses these users are logged in from (:0 is localhost).

On this note, TTY is the local text based terminal at the machine, while PTS is a pseudo-terminal. This is most likely an SSH session or similar, anything that’s happening remotely.

who can also show us who we are, in case you’re ever logged in on a system and don’t know which user you are:

You can also concatenate who am i into whoami.

The last command

The last command can take a moment to execute and will show a list similar to this:

You can see who has logged in to the system recently, from which IP address, and when each session started and finished. You can also see when the system was last restarted (and in Linux, which Kernel was used to do so).

The last line (on Linux, beginning with wtmp) shows since when the command was able to display results. last and who both read a file called wtmp (in /var/log/wtmp), which logs all login attempts over time.

last accepts several filtering options too. For example, to query when a particular user has logged on and off, type last followed by the username:

Or if you’re only interested in restarts:

On OS X the output is somewhat more limited due to the absence of kernels, but it works just the same. For more information on each command, checkout the man pages with man last and man who.

  • http://osxdaily.com/2014/03/25/see-users-who-connected-to-mac/
  • http://unix.stackexchange.com/questions/21280/difference-between-pts-and-tty
  • http://www.linuxnix.com/read-view-utmp-wtmp-btmp-file-linuxunix/

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

Add your voice!