How To List Users In Linux | LinuxHostSupport
Maybe your like

In this tutorial, we’ll be going over how to list the users that have been created on your Linux system. This applies for all distributions, and is very easy to do.
The users on your system can be either normal “human” users or system users. The normal users are usually other people that can log in and interact with your server, while the system users are used to start non-interactive background services. You might even create users for certain software platforms to have a user that grants them access to certain files and directories. Let’s begin.
Step 1. Connect to your server
To connect to your server via SSH as the root user, use the following command:
ssh root@IP_ADDRESS -p PORT_NUMBERand replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number. Of course, you can also replace root with the username of any user you’d like, as all users can view the list of users on the system.
Step 2. The /etc/passwd file
In Linux, there isn’t any specific command that can list all users in your system. However, there is still a way to extract this information from our system. One important file that stores user information in your system is the /etc/passwd file.
The /etc/passwd file is a text file that stores all of the required information about all of the users that exist on our system. Each entry in this file can have up to seven fields (separated by the colon “:” symbol) and each field contains some important information about that user. Here is an example of one entry for a user called “linux-user” stored in /etc/passwd:
linux-user:x:1000:1000:Linux User:/home/linux-user:/bin/bashAnd here is an explanation of each of the fields in this entry:
- Username – this is the name of the user, in our example “linux-user”
- Password: this field contains the encrypted password of the user, marked with “x”. The encrypted password is stored in the /etc/shadow file in our system and can only be accessed by the root user.
- User ID number (UID) – this field contains a unique number for each user. The number 0 is reserved for the root user
- Group ID number (GID) – this is the ID number of the group, which is stored in the /etc/group file
- User Info: this field contains all additional user information such as the user’s real name, phone numbers and other information.
- Home Directory: this field contains the path of the user’s home directory. In our example, the home directory of the “linux-user” user is /home/linux-user
- Login shell: this field contains the path of the user’s login shell, for example /bin/bash
3. List all users on your Linux system
Now that we know about the existence of the /etc/passwd file and the information it contains, we can simply use the cat command to print all the contents of this file. You can then look at the first field of each entry which shows the name of each user in your system:
cat /etc/passwdOutput example:
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 . . . . . . sshd:x:104:65534::/var/run/sshd:/usr/sbin/nologin mysql:x:109:114:MySQL Server,,,:/nonexistent:/bin/false linux-user:x:1000:1000:Linux User:/home/linux-user:/bin/bashIf you want to list only the first field for each user, which contains the actual username, you can use the cut or the awk command. For example:
cut -d: -f1 /etc/passwdor
awk -F: '{ print $1}' /etc/passwdBoth commands will give you the following output:
root daemon bin sys sync games man lp mail . . . . . . sshd mysql: linux-userAnother way to list all users in your Linux system is with using the getent command.
The getent command displays all entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf
This file also contains the passwd database, so you can now use the following command again where you will get the list of all entries included in the passwd database:
getent passwdHow to Find if a Specific User Exists in Your System
Instead of listing all users, you may also want to check if any specific user exists on your Linux server. To do this, you can combine one of the previous commands with the grep command. For example, if you want to check whether the “linux-user” user exists on your server, you can type the following command:
cat /etc/passwd | grep linux-userIf the user exists, the following output should be displayed on your screen:
linux-user:x:1000:1000:Linux User:/home/linux-user:/bin/bashBy this point, you now know how to see what users exist on your server, as well as search for a specific user on your server.
Of course, if you are using one of our Managed VPS Support services, you can simply ask our expert Linux admins to help you and give you a list of all users on your Linux VPS, along with any other system-related questions or requests. They are available 24×7 and will take care of your requests immediately.
PS. If you liked this post on how to list all users in Linux, please share it with your friends through social media by using the share shortcuts, or simply leave a comment below. Thanks.
Tag » Where Are Users Stored In Linux
-
How To View System Users In Linux On Ubuntu - DigitalOcean
-
Where Does Linux Store Its Users? - Quora
-
How To List Users In Linux
-
How Linux Stores User Account Information | Beginning Fedora 2
-
Where Are The Passwords Of The Users Located In Linux? - NixCraft
-
6.3.2. Files Controlling User Accounts And Groups
-
Where User Account And Group Information Is Stored
-
How To List Users In Linux {4 Methods Explained} - PhoenixNAP
-
2. How User Information Is Stored On Your System
-
Where Are User Files Stored In Linux? - Systran Box
-
Where And How Are Passwords Stored On Linux
-
Linux Directory Structure: /home And /root Folders
-
Linux Home Directory - Javatpoint
-
Understanding Linux User Accounts - OES 2018 SP2