After I got back from my trip to Puebla, Mexico to taste and learn about Pulque. My friend called me looking to find out how to check users group in Linux. There are some steps I took to find users and groups in Linux.

Steps to check users on a Linux server

Use the cat /etc/passwd command to view the contents of the /etc/passwd file, which contains information about all the user accounts on the system.

Alternatively, you can use the getent passwd command to query the system’s user database and list all the users.

To get a count of the total number of users, you can pipe the output of the cat /etc/passwd or getent passwd commands to the wc -l command to count the number of lines, which corresponds to the number of users.

If you only want to list the normal user accounts (excluding system accounts), you can use the getent passwd {1000..60000} command to list users with UIDs (User IDs) in the typical range for normal user accounts.

You can also use the awk command to extract just the usernames from the /etc/passwd file, for example: awk -F':' '{ print $1 }' /etc/passwd

How to check a user’s group?

You can use the groups command:

groups

This will list all the groups the current user is a member of.

To check the groups for a different user, use the following syntax:

groups <username>

Use the id command to get more details about a user:

id <username>

This will show the user’s primary group, as well as any secondary groups they belong to.

Another option is to use the getent command to query the system’s user database and list the groups a user belongs to:

getent group | grep <username>

The above will show all groups the user is a member of. Usually will highlight the username.

If you want to see all the users that belong to a specific group, you can use the following command:

getent group <groupname> | cut -d: -f4

To check users group Linux is quite easy, but if you don’t do this on a daily basis is easy to forget. This is my case. You can always contact me if you have any questions or want to collaborate. Thanks!

Leave a comment

Your email address will not be published. Required fields are marked *