
To configure and manage permission system admin needs list of all users. There are commands to create user, delete user but it’s critical task to list all users in Linux system. This tutorial will show you how to list users in Linux systems.
List all users using /etc/passwd file
User information is stored in /etc/passwd
file. It contains one line with username for each user account on system. You can use less
or cat
command to see file contents:
cat /etc/passwd
It will show you output as below :

In above output you can see that, each line has seven fields delimited by colons that contain the following information:
- Username
- Encrypted password where x means password is saved in etc/shadow file.
- UID (User ID)
- GID (User’s Group ID)
- Full Name of User
- User $HOME directory
- Login shell path
If you want to list only username then you can use awk
or cut
commands to print only the username:
awk -F: '{ print $1}' /etc/passwd
cut -d: -f1 /etc/passwd
Output will be as following:
Output
root
daemon
bin
sys
sync
games
man
lp
news
uucp
proxy
www-data
...
...
geoclue
gdm
gnome-initial-setup
sshd
List all users using getent command
Getent command will read entries from databases. It will list users from both LDAP
database and /etc/passwd
file.
To get a list of all Linux users type the following command:
getent passwd

Output will be same as contents of /etc/passwd
file. You can also use awk
or cut
to print only the username:
getent passwd | awk -F: '{ print $1}'
getent passwd | cut -d: -f1
Check If a user exists in the Linux system
Now we know how to get list of users. But what if you want to check if a user is exists on current system or not. You can check using grep command and without using grep command.
For example, we want to check that tecnstuff user is exists or not then you should issue command as below:
getent passwd | grep tecnstuff
getent passwd tecnstuff
Output
tecnstuff:x:1001:1001:,,,:/home/tecnstuff:/bin/bash
If user will exists in system then it will print details of that user otherwise it will not print anything.
If you wants total number of users exists on your system then you can get it by :
getent passwd | wc -l
It will return number of users as following output:
Output
47
Differentiate System and Normal Users
System users are created when you are installing OS or updating new packages. There is no more difference between system users and normal users.
Normal users are the users created by the root or another user with sudo privileges. Usually, a normal user has a real login shell and a home directory.
Each user has a UID (User ID) either he is system user or normal user. When normal user adds user by using adduser command. User will be added and UID will be assigned automatically with reference of UID_MIN and UID_MAX from file /etc/login.defs.
You can check UID_MIN and UID_MAX by below command:
grep -E '^UID_MIN|^UID_MAX' /etc/login.defs
It will show output as below:
Output
UID_MIN 1000
UID_MAX 60000
From the above output, we can see that all the normal users should have unique ID between 1000 and 60000.
Now we will issue command to get list of normal users whose unique ID between 1000 and 60000.
getent passwd {1000..60000}
Output
tecnstuff:x:1000:1000:TecNStuff,,,:/home/tecnstuff:/bin/bash
demouser:x:1001:1001:,,,:/home/demouser:/bin/bash
To print only usernames type following command:
eval getent passwd {$(awk '/^UID_MIN/ {print $2}' /etc/login.defs)..$(awk '/^UID_MAX/ {print $2}' /etc/login.defs)} | cut -d: -f1
Output
tecnstuff
demouser
Get Groups List in Linux
You can list all groups in Linux by using the following command.
getent group
You can get list all groups with specific user using following command:
getent group | grep tecnstuff
Conclusion
You learned how to list users in Linux system and also differentiate difference between normal user and system user. Same commands will be used for all the Linux distributions.
If you have any question or suggestion leave comment below.
Leave a Reply