Need to list users in CentOS 7?
This guide will help you.
Listing users in CentOS 7 is commonly done before adding a new user or checking if a user already exists.
Here at Ibmi Media, as part of our Server Management Services, we work with CentOS 7 Servers on a daily basis.
In this context, we shall look into different commands to list users in Linux.
What are the commands to list users in CentOS 7?
The following commands are used by our Support engineers to list users in CentOS.
We start by logging into the Server via an SSH tool, then we can run the commands below and get the information you need.
1. To get a simple list of usernames.
Enter the command given below:
cut -d: -f1 /etc/passwd
This command gives us a list of users assigned to this CentOS server including system users like:
[Need further assistance with CentOS Software Installation? We are here for you!]
2. The getent command.
This command will also list user details as it pulls info from the passwd, group and other databases that stores the users information.
The databases used in searches in are:
ethers (Ethernet addresses)
a) To search for a specific service noted in the services database
The following command lists the service currently running on port 22:
root@host [~]# getent services 22
We can check with the port number of the service we wish to see.
b) The getent hosts command lists the recognized hosts:
root@host [~]# getent hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
127.0.0.1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.67.227 host.domain.com host host2.domain.com host2
c) To get a more detailed list of users, we can use the command below.
Using this command will provide you with the username, UID, GID, User Details, their home directory path, and the Default Shell type for the user.
We are using 'root' as the user along with the command.
root@host [~]# getent passwd root
[Need further assistance with Linux Software Installation? We are here for you!]