While working on a Linux machine, you will very likely have a “What the heck just happened and who the heck just did it?” moment. This is when you’ll want to quickly see who’s currently logged in.
Before you go any further, you should acquaint yourself with the concept of a utmp file (possibly also known as the utmpx file). A utmp file keeps track of currently logged on users and is what any command will ultimately reference to bring you the desired information.
Firstly, you can try the `users` command. However, the information garnered is pretty sparing. It’s merely a username repeated as many times as there is a login session for it. In my case, on my laptop at the very moment I write this, I see this:
[wesley@Fedora1530 ~]$ users wesley wesley wesley wesley
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT wesley tty1 :0 Tue12 39:54m 1:34m 0.06s pam: gdm-password wesley pts/1 :0.0 Tue16 1:38m 0.45s 0.44s ssh email@example.com wesley pts/3 :0.0 Tue16 1:38m 0.49s 0.47s ssh firstname.lastname@example.org wesley pts/5 :0.0 Tue20 0.00s 0.25s 0.03s w
That is considerably more information. The default output of `who` looks like this:
wesley tty1 2012-02-14 12:28 (:0) wesley pts/1 2012-02-14 16:24 (:0.0) wesley pts/3 2012-02-14 16:34 (:0.0) wesley pts/5 2012-02-14 20:46 (:0.0)
`Who` defaults to simply showing the Name, Line, Time and Comment columns (at least my version on Fedora 14) however many other bits of information can also be added. Check the appropriate man pages.
Once you know who is logged in, whether or not you then harass them with ‘write‘ or pkill everyone who isn’t you is completely up to your discretion.
How do you like to figure out who is logged into your machine? Any pro tips?