How to list users on Ubuntu 20.04

The objective of this article is show the reader how to extract a list of users on the Ubuntu 20.04 Focal Fossa Desktop/Server.

In this tutorial you will learn:

  • How to list users on Ubuntu 20.04

How to list users on Ubuntu 20.04

How to list users on Ubuntu 20.04

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to list users on Ubuntu 20.04 step by step instructions

  1. The first method to list all users on Ubuntu 20.04 is to show the content of the /etc/passwd file. To do so execute the following command:
    $ cat /etc/passwd
    

    The above command will list all usernames as per first column of the above command output. The 3rd and 4rd columns represent UID ( user ID ) and GID ( group ID ).

    list users on Ubuntu 20.04

    The UID of a regular users is >= 1000 whereas UID of the administrative user root is always 0.

    In case you need only usernames, you can extract only the first column of the /etc/passwd file:

    $ cut -d: -f1 /etc/passwd
    


  2. Another alternative is to use the compgen command to export the list of users on your Ubuntu 20.04 system. Example:
    $ compgen -u
    
  3. Lastly, the getent command can be also used to get user names entries from the /etc/passwd file:
    getent passwd