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.
ps
(hence a comment instead of an answer) but would something likeps -aux | tail -n+2 | cut -d' ' -f1 | sort -u
work? Of course, that also includes system users running non-interactive processes, but we can work on that if you think this is a promising avenue to pursue. – terdon Nov 02 '20 at 16:26getent
. – terdon Nov 02 '20 at 17:23ps
". Sinceps
is the tool to query active processes, could you clarify whyps
is not allowed? – Jeff Schaller Nov 02 '20 at 17:50/proc
(from the same placeps
gets it)grep Uid: /proc/*/status
, etc ;-) Keep in mind that a user id is simply a number, and any privileged process can justsetuid(some_uid)
, without it having to go through pam/utmp, and withoutsome_uid
having to exist in any database, or have attached to it a name or a home directory. The only way to get a list of all active uids is to look through all the processes running on that machine. – Nov 02 '20 at 22:31