Ubuntu List Users - 6 Easy Commands

Reading time icon 5 min. read

Readers help support MSPoweruser. When you make a purchase using links on our site, we may earn an affiliate commission. Tooltip Icon

Read the affiliate disclosure page to find out how can you help MSPoweruser effortlessly and without spending any money. Read more

ubuntu list users

Wondering how to use Ubuntu to list users? Since it’s a multiuser operating system, it allows multiple users on different terminals or computers to access a single system. However, you’ll want to list user accounts for better management.

In this guide, I’ll discuss some essential commands to achieve this with ease.

Let’s roll in!

Why Is It Important To List Users on Ubuntu?

Listing users offers several benefits such as:

  • System Administration: You can list Ubuntu users to verify the account status, check permissions, and perform other maintenance tasks like account deletion and password resets.
  • Security: Identifying and monitoring users on your Ubuntu system assists in detecting unauthorized accounts that might pose security threats.
  • Resource Management: Being a Linux administrator, you can identify which users are consuming the most resources. This helps you optimize the system performance.
  • Documentation and Reporting: Getting information about all system users helps the IT teams document configurations and setups.
  • Collaboration: You can check if specific users have system accounts or find a user with whom you need to collaborate on particular projects.
  • Troubleshooting: You can utilize the list of users to find conflicts or issues.

How To List Users on Ubuntu

Let’s explore the following six commands to list users on Ubuntu:

1. Using the cat Command

In Linux-based operating systems, the “etc/passwd” file contains a list of configured users along with the relevant information for each. Moreover, you can use the cat command to view its content on the terminal.

To do so, press CTRL+ALT+T to open your Ubuntu terminal. Type “cat /etc/passwd” and hit Enter.

listing ubuntu users with cat command

As a result, you’ll see a list of users, where each row of the table displays extensive details such as:

  • Username
  • Password (where x indicates a password for the respective user)
  • User ID (UID)
  • User’s Group ID (GID)
  • Optional info (including full name, phone number, room number, etc)
  • Home directory
  • Default login shell

For a better understanding, check out the following diagram:

understanding the pattern in the /etc/passwd file

2. Using the less Command

On Ubuntu, the less command is used for reading the content of a text page one page at a time. In this case, I’ll use it to view the “/etc/passwd” file and list all users on my Ubuntu terminal.

For this, I’ll run the less “/etc/passwd” command, which will give the following output.

listing ubuntu users with less command

3. Using the getent Command

The getent command helps you get entries from important text containing user information such as passwd and group databases.

Now, to list the entries of the “/etc/passwd” file, I’ll run the “getent passwd” command.

listing ubuntu users with getent command

4. Using the awk Command

awk command is useful when you want to display only the username. For instance, when you’re writing a script to perform any operation on multiple user accounts. In this scenario, listing usernames only and redirecting them to a text could be a time saver.

Here, I’ll add the -F option as a field separator option with “:” to print only the first field from the “/etc/passwd” file that represents the usernames.

listing ubuntu users with awk command

5. Using the cut Command

You can also achieve the same output with the cut command. For this, redirect the output of “/etc/passwd” to the cut command using the pipe operator “|”. Add the -d option as a delimiter and -f to only select the first field.

For instance, I’ll type “cat /etc/passwd | cut -d: -f1” command.

listing ubuntu users with cut command

6. Using the compgen Command

The compgen command with the -u option lists the user accounts on the terminal. Moreover, you can pipe its output to the column command to list usernames in columns rather than a single long list.

For the demonstration, I’ll execute the “compgen -u | column” command.

listing ubuntu users with compgen command

How To List Only Currently Logged-in Users on Ubuntu

To list only currently logged-in users, you can use:

Using the who Command

In Ubuntu, the who command displays the login name of the current user, terminal line numbers, the login time, and the remote hostname.

Now, to list the currently logged-in users with the mentioned details, I’ll type the “who” command in the terminal.

listing only currently logged-in users with who command

According to the given output, “author” is the current logged-in user on my Ubuntu system.

Using the w Command

The w command in Linux provides a quick summary of who is currently using the system, how much the system is being used, and what programs are currently running.

Now, I’ll run the “w” command.

listing only currently logged-in users with w command

In the above output:

  • USER represents my username as the currently logged-in user.
  • TTY displays the terminal device associated with my current session.
  • FROM indicates the remote host to which I’m connected.
  • LOGIN@ shows the time at which I’ve logged in to the system.
  • IDLE represents the duration of inactivity since my last interaction.
  • JCPU indicates the CPU time used for all processes linked to my session.
  • PCPU displays the percentage of CPU time used in the current process.
  • WHAT displays the details related to a process or command running in my session.

Bonus Tips:

To check the name of the currently logged-in user, type “users” in your Ubuntu terminal.

checking the name of currently logged-in ubuntu users

To get information about a particular user on Ubuntu, run “grep username /etc/passwd“. Here, I’ll check out the details of the “author” user.

getting information about a specific user on ubuntu

To count the total number of users on Ubuntu, use the wc command with cat as “cat /etc/passwd | wc -l“.

counting ubuntu users with wc command
checking range for user IDs on ubuntu

To check the range for user IDs, execute the “grep -E ‘^UID_MIN|^UID_MAX’ /etc/login.defs” command.

You may also be interested in:

Choose any of the discussed approaches to review the user accounts. Note that these commands can run on all Linux distributions including Ubuntu. Moreover, none of them need sudo access which means they’re available to every user.

Now that you know how to use Ubuntu to list users, share your favorite method in the comments below!

More about the topics: Ubuntu