How to List Linux Users on Ubuntu
Listing All Users on Linux
Linux stores all the information about user registrations in a file called /etc/passwd.
To access the content of the file, open your terminal and type the following command:
less /etc/passwd
The script will return a list that looks like this:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3ys:/dev:/bin/sh
...
In the output above, each line corresponds to a user. The number of lines will depend on the number of registered users.
Each line contains seven fields that are separated by colons (:). These fields hold specific information about a particular user.
Let's take a look at the first line:
root:x:0:0:root:/root:/bin/bash
Here are the meanings of each field, from left to right:
- root — the login name of the user.
- b — placeholder for the password (the actual password is stored in a separate file).
- 0 — User ID, which is unique for each registered user. By default, root has the User ID of 0.
- 0 — Group ID. Like User ID, it is unique for every user.
- root — Comment field. Contains a short description of the user, usually filled out with users’ full name.
- /root — Home directory. This is the main directory of the users. For users other than root, the folder will be
/home/username. - /bin/bash — User shell. Refers to the shell that users use to sign in to the system.
If you only want to view the name of the users, you can run this special command:
cut -d : -f 1 /etc/passwd
Listing User Groups on Linux
In Linux, you also have the option to create groups. You basically gather several users and grant them joint privileges or access. It is particularly useful if multiple teams are using the same system.
Unlike users, the group information is stored in a file named group that can be found at /etc/group.
To list the contents of this file, simply open up the terminal and type the following command:
less /etc/group
The line above should give this output:
Root:x:0: Daemon:x:1: Bin:x:2: Sys:x:3: . . .
Notice that the group names are exactly the same as the name of our users. This is the result of user private groups (UPG), a scheme employed by Linux where each user will have their own private group.
Just like the previous one, it is possible to view the group names only:
cut -d : -f 1 /etc/group
Listing Logged In Users
To list logged in users, simply type the following letter in your terminal:
w
Besides showing the active users, the command also provides some additional information like login time, remote host, and idle time. The full results will look like this:

Let's breakdown the results of the w command:
- User — username.
- TTY — terminal name.
- From — the name of the remote host.
- Login@ — login time.
- Idle — idle time.
- JCPU — the amount of time used by processes attached to the TTY.
- PCPU — the time used by the process displayed in the WHAT field.
- WHAT — the user's current process.
Alternatively, there is another command that performs a similar function to w:
who
However, the results won't be as detailed as the w command:
root pts/0 2019-10-21 10:02


ys:/dev:/bin/sh