How to find which users belongs to a specific group in linux
This sneppet guides you on how to find which users belongs to a specific group in linux. I am going to use my GCP cloud shell to show the commands for you. Let’s see in detail.
Find which users belongs to a specific group in linux
Let’s assume you are looking for how to find list of users who belongs to a group, so that you can manage file or folder permissions for giving some access.
First, you need to check list of all groups for your reference. Execute the following command to get list of all groups.
$ sudo groups root google-sudoers
From the above response you can see that there are two groups (root and google-sudoers).
To find which users belong to specific group in linux, you need to run the following command in the linux terminal.
$ sudo grep '^<groupname>:' /etc/group
For example, the following command list users belong to group “google-sudoers”
$ sudo grep '^google-sudoers:' /etc/group google-sudoers:x:1001:sneppets,root
Therefore, the users (sneppets and root) belong to group “google-sudoers”.
Similarly, to get list of all groups a specific user belong to, you need to execute the following command from the terminal.
$ sudo groups <username>
For example, to get list of all groups the user “root” belong to, run the following command.
$ sudo groups root root : root google-sudoers
Therefore, the user “root” belong to groups (root and google-sudoers)
That’s it. You had learnt how to list all groups and how to find list of all users who belongs to specific group.
Hope it helped 🙂
- Create non-root SSH user account and provide access to specific folders
- Docker: Error response from daemon: OCI runtime create failed: container_linux.go:349
- How to unzip a zip file from Terminal (Google Cloud Shell)
- Build a Docker Image with a Dockerfile and Cloud Build in GCP?
- How to create GCP project on Google Cloud Platform
- GCP Virtual Private Cloud (VPC) Networks Fundamentals
- How to create GCP project on Google Cloud Platform
- Is it possible to change Google Cloud Platform Project ID ?
- How to connect VM using private key and SFTP in WinSCP ?