On Linux, there are many different tools for creating new users. Each Linux desktop environment has a user manager, and these user managers, while very handy, come up short. None of them support viewing hidden system users such as root, dbus, etc.
If you’ve been trying to get a complete list of all users on your Linux PC but don’t know where to start, this guide is for you. Follow along as we show you how to list all users on your Linux system, including ones that don’t appear in your Desktop Environment’s user manager.
Linux list all users – cat
The easiest way Linux users can view all of the system’s users is by using the cat command on the
/etc/passwd file. The
/etc/passwd contains lots of information, like passwords as well as user information.
To list all of the users on your Linux PC via the cat command, start by opening up a terminal on the Linux desktop. To open up a terminal on the Linux desktop, press the Ctrl + Alt + T keyboard command, or search for “Terminal” in the app menu.
Once the terminal window is open, execute the cat command below to view the contents of the file. Keep in mind that unencrypted passwords are not stored in the /etc/passwd file. Instead, just encrypted references to each password are present.
If you’d like to save the /etc/passwd cat output to a text file for your own use, here’s how to do it.
cat /etc/passwd > ~/passwd-file
You can view your ‘passwd-file’ at any time in the terminal window the same way you viewed the
/etc/passwd file. By making use of the cat command.
Linux list all users – cut
Another way to view all users on the Linux system is with the cut command. Cut is a great way to go because, unlike cat, cut can filter out unwanted text, whereas the cat command can only view the contents of a file verbatim.
To view the list of users on your Linux PC with the cut command, make sure a terminal window is open. To open one, search for “Terminal” in the app menu on your Linux PC.
With the terminal window open, make use of the following cut command to view the list of installed users on your Linux PC.
After executing the cut command, you should see a long list of all of the present users on your Linux PC. This list is likely long. If you want an easier time reading this list in the terminal, combine the cut command with the less command.
cut -d: -f1 /etc/passwd | less
By combining the less command with cut, you will be able to press the “Enter” key on the keyboard to view the user list line-by-line, rather than all at once.
Want to export the list of users generated by the cut command to a text file for use later? Enter the command below.
cut -d: -f1 /etc/passwd > ~/cut-user-list
To view the list later, execute the cat command.
Linux list all users – compgen
A third way to list all users on a Linux system is by making use of the Compgen tool. Compgen is a built-in tool included in the Bash command-line. It can be used to list all available commands that users can execute in the Bash terminal.
Compgen does not need to be installed on any Linux operating system. Furthermore, Compgen isn’t packaged by any Linux distribution, and there’s no way to download it to your computer. Instead, everyone running Bash on Linux automatically has it set up and ready to go.
To view all available users on your Linux PC with compgen, you will need to make use of the -u command-line switch. Using the command below, list all users on your Linux system.
After executing the above command, compgen will print out a long list of every user on your Linux system. If you’d like a more comfortable way of looking through this long list, try combining the compgen command with the less command.
compgen -u | less
By executing the compgen command with the less command, the user list will be divided into pages. You can go through these pages by pressing the “Spacebar” button on your keyboard.
Want to save the compgen user output to a text file for use later on? Pipe it to a text file with the command below.
compgen -u > compgen-user-list
To view the Compgen text file you’ve exported, make use of the following cat command.