How To List Users in CentOS 7?
Listing users in CentOS 7 is commonly done before adding a new user or checking if a user already exists.
At Bobcares we often come across this for servers with CentOS7 as a part of our Server Management Services.
Today let’s see how our Support Engineers handle this with a few easy steps.
Commands used to list users in CentOS 7
The following commands are used by our Support engineers to list users in CentOS.
First, we have to log in via SSH, 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:
daemon operator sshd systuser cpanel clamav dovecot
[Need further assistance? 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:
ahostsv4 ahostsv6 aliases ethers (Ethernet addresses) group gshadow hosts netgroup networks passwd protocols rpc services shadow
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
ssh 22/tcp
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
root:x:0:0:root:/root:/bin/bash
[Need further assistance? We are here for you!]
Conclusion
In this article, we discussed how to list users in CentOS 7. Also, we saw the simple methods that our Support Engineers use to list the users easily.
0 Comments