How to List All User Accounts on Ubuntu 16.04 / 18.04

On most Linux systems, including Ubuntu, there’s not a single program or tool to list all user accounts on the system… If you’re using the desktop GUI, you may be able to see all the user accounts as an administrator..

How about on servers? How do you list or view all user accounts?

Since there is no single tool to list users, we usually depend on system files to list the users… All system accounts created are stored in multiple files on the server… and listing the content of these files, we can find out the list of users and groups..

This brief tutorial shows students and new users how to list user accounts on Ubuntu…Again, there are multiple ways to find out the user accounts on Ubuntu… Below are commands that when used, show you all users accounts on Ubuntu and other Linux systems…

Option 1: List User in the passwd file

One popular option for listing user accounts on Ubuntu is to view the content of the /etc/passwd file…

This file store local user account information from login name to the encrypted password and account ID… So to view all user accounts on the system run the commands below:

less /etc/passwd

When run the commands above, it should list the content of the /etc/passwd file… In there you’ll see all the accounts created on the server…

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
........

You can also use the cat /etc/passwd command to output the same list…

For students and new users this can be confusing if they don’t know how to read the content of the file… However, each line in the file is  a single account identity… there are seven fields delimited by colons that contain the following:

  • User name
  • Encrypted password (x means that the password is stored in the /etc/shadow file)
  • User ID number (UID)
  • User’s group ID number (GID)
  • Full name of the user (GECOS)
  • User home directory
  • Login shell (defaults to /bin/bash)

Now, if you just want to list the account names and not all the other details, simply run the commands below:

awk -F: '{ print $1}' /etc/passwd

That should list only the account names on the system beginning with the root account..

root
daemon
bin
sys
sync
games
man
......

That’s option number 1

Option #2: Get User List via Getent Tool

Another option to get all user account on the system is to use the getend tool… This tool does similar function as the commands above.. It lists the content of the /etc/passwd file using the database info stored in the /etc/nsswitch.conf file..

To get the lists of users using the getent, run the commands below:

getent passwd

It should list the same content as above:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
........

The /etc/nsswitch.conf  is used to configure which services are to be used to determine information such as hostnames, password files, and group files…

These two options should be enough to get you list of users on Linux systems, including Ubuntu

You may also like the post below:

How to Change MySQL / MariaDB User Passwords on Ubuntu 16.04 / 18.04

One Reply to “How to List All User Accounts on Ubuntu 16.04 / 18.04”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.