How to list all logged-in users

To see the connected users on your server, you can use the shell commands: w, who or users. You can use the three commands without any parameters. For more options run the commands with the –help argument.

In the examples below, you can see three logged-in users – you can see their IPs, logged-in time etc.

The w shell command:

root@s04 [~]# w
 01:42:08 up 22 days, 23:37,  3 users,  load average: 0.43, 0.58, 0.66
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    92.168.15.13     01:40    1:12   0.04s  0.04s -bash
tony     pts/1    71.162.88.56     01:41    8.00s  0.03s  0.03s -bash
adam     pts/2    79.102.18.24     01:48    0.00s  0.03s  0.00s w

As you can see, the header of the result will show the current time of the server, the uptime, how many users are connected and the server load for the last 1, 5 and 15 minutes.

The next lines will show for each user – the login name, tty name, the Ip of their host, login time, idle time, JCPU, PCPU, and the current command line.

The who shell command:

root@s04 [~]# who
root     pts/0        Jan 19 01:40 (92.168.15.13)
tony     pts/1        Jan 19 01:41 (71.162.88.56)
adam     pts/2        Jan 19 01:48 (79.102.18.24)
linux who
who command

The who command is very similar to w.

The users shell command:

root@s04 [~]# users
root tony adam

This command will only list the usernames.

Resources:
w man page
who man page

Leave a Reply