How can I list all currently logged-in users?
9
votes
3
answers
27156
views
I have a system I'm managing (running RHEL 8) that has multiple users in our small office, who log into it in various ways -- locally at the console, remotely via SSH and NoMachine Workstation. When I do updates that include a new kernel, or for some other reason I need to reboot the machine, I'd like to make sure there are no currently logged-in users, so I'm not interrupting users who are running software on the machine.
So what I'd like to have is a command that lists all currently logged in users.
I've done quite a bit of searching on this topic, and the methods I've found in response to this question are simply wrong, in the sense that they provably do not work.
The commands
who
, w
, and users
do **NOT** list **all logged-in users**. As I'm writing this there are three users currently logged in to the computer in question, including myself. These commands list only one of these three (incidentally, I'm not one of them). The one user who is listed by these commands is logged in via SSH and has an open terminal. Another user who has no TTY but has several GUI applications open with their X displays piped to his laptop through SSH does not appear, and neither do I (I have a graphical login via NoMachine). In fact, who -m
returns no output when I run it. I can use ps -ef
to list all processes and find processes currently running for all these users.
The command last | grep 'still logged in'
(suggested here ) results in the same incomplete list as above (it's getting its information from the same source).
So, repeating the question -- what is the definitive method to get a list of all logged in users (users who have authenticated via the normal mechanisms, and have interactive processes currently running under their user IDs) ? I'd like to do this without searching through the output of ps
.
EDIT -- The users on this workstation are all authenticating via LDAP, however I've verified that this is not related to the question. I have created a local user account, which also does not show up in response to who
or users
when logged in by the same means as described above.
Asked by Chris Robison
(193 rep)
Nov 2, 2020, 04:19 PM
Last activity: May 13, 2025, 08:10 PM
Last activity: May 13, 2025, 08:10 PM