How To List Users In Linux (Ubuntu, Mint, Debian, CentOS)?

Users are one of the most important parts of the Linux operating systems like Ubuntu, Debian, Mint, Kali, CentOS, etc. By creating user accounts different users and people can log in and use the Ubuntu system with their own permissions, files, and configuration. This tutorial can be used to list users in VM, Guest, VPS, or VMware Linux systems. Alternatively, the following commands can be used by connecting remote Linux systems via SSH. This SSH connection can be done with a tool like PuTTY or native ssh client of Linux system.

User Database File /etc/passwd

The Linux users and related information like shell type, user id, etc are stored in passwd file which is located /etc/passwd. This file can be read by all users but only changed by administrative users and the root user. The content of the passwd file can be printed with the cat command like below. Different commands like cat, less, more can be used to print this user list into the terminal.

$ cat /etc/passwd
List Linux Users with Related Information
  • Username is the official name of the user which will be verified during logins or SSH connections.
  • The encrypted password is depicted as x because it is sensitive information and stored in the /etc/shadow file.
  • User ID (UID) is the user’s numerical and unique number.
  • User’s Group ID (GID) users own group numerical and unique number.
  • Full name is the name and surname of the user.
  • Home Directory is the path of the user’s home directory where the private files and folder are stored.
  • Login Shell is the user’s default shell which will be provided for console and terminal access.

As an example take a look at the following line which provides details about the Linux user named ismail. The columns are separated with the “:“. If there are multiple information in the same column they are separated with “,“.

ismail:x:1000:1000:İsmail Baydan,,,:/home/ismail:/bin/bash
  • The username is “ismail“.
  • The password is encrypted and stored in /etc/shadow file.
  • The user ID or UID is 1000.
  • The group ID or GUID is 1000.
  • The full name of the user is “İsmail Baydan“.
  • The user home directory is “/home/ismail“.
  • The user uses “/bin/bash” as shell.

List Users with cat Command Via /etc/passwd File

As stated previously the users and related information is stored inside the /etc/passwd file. This file is column are separated with semicolons where the user name is the first column. The user’s names can be extracted by using tools like awk, cut, etc. and only the user names can be printed.

$ cut -d: -f1 /etc/passwd

The output will be like below where the username will be listed according to the line sequence.


We can also sort these users according to their user names but using the sort command like below. We will just redirect the cut command output into the sort command where the usernames will be sorted and listed alphabetically which starts from a.

$ cut -d: -f1 /etc/passwd | sort

Also the awk command can be used like below to list only linux user names.

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

List Users with getent Command

The getent command is used to display users from the database configured with /etc/nsswitch.conf and /etc/passwd. The nsswitch.conf is used to configure an LDAP source which will be generally an active directory to manage users from a centralized source. The getent command is the most complete command to list users because it also provides the LDAP users if the current Linux system if it is configured with LDAP.

$ getent passwd

Like previous way the cut and awk commands can be used to extract only user names from the getent command output.

$ getent passwd | awk -F: '{ print $1}'

or the cut command can be used like below. The delimiter is set with the -d option the it will be “:”. The -f1 is used to select the first column which contains the usernames.

$ getent passwd | cut -d: -f1

Check If User Exist

A typical Linux system contains a lot of users for the system related jobs and normal users which are human. Searching and finding a specific user or username in the output of the user listing commands can be error prone and trivial task. You can use the grep command in order to search for a specific user or username wheter it exist. If the user exist in the linux system the user name line will be printed to the terminal and if not exist there will be no output about the user.

$ getent passwd | grep "ismail"

or with the cat command;

$ cat /etc/passwd | grep "ismail"

The output is like below which means the user ismail exist in the current linux system.

Check If User Exist

Leave a Comment