This tutorial will be helpful for beginners to List users in the Linux systems. In Linux, the user accounts will be in the /etc/passwd file.
/etc/passwd file contains the local user’s information and this file is in a human-readable format. For opening the file we can use cat / more / less / grep or egrep command
List all Users in Linux
2 ways to list the users in linux
- cat /etc/passwd
- getent passwd
If you are noticing the output of the file, each line contains 7 fields and it is explained below
- adminpc – User name
- x – represents the password is in encrypted and stored in the /etc/shadow file
- 1000 – User ID number
- 1000 – Group ID number
- adminpc,,, – represents the full contact details of the user name.
- /home/adminpc – User home directory.
- /bin/bash – Login shell assigned for the user.
Use the following command to list all the local users in the system
Search for specific users eg: root using getent
Display only users names using getent , in this case we can use awk or cut command to list only user names