How To Find Out Which Groups A User Belongs To In Linux
The other day I was installing Dropbox on Ubuntu 18.04 LTS server edition. When configuring Dropbox, I needed to enter my current user name and the group name. Of course, I know (and any experienced users) how to easily find out which groups a user belongs to, but not the newbies. So, I thought it would be helpful for the newbies if I post the procedures to find out which groups a user belongs to in Unix-like operating systems in our blog, hence this tutorial. Read on.
Find Out Which Groups A User Belongs To
In Unix-like operating systems, the groups command displays the current group names and the users belongs to those groups.
First, let us take a look at how many groups are there in my Linux system. Entering the groups command without any argument will display the available groups.
$ groups wheel network audio optical storage power users vboxusers
As you can see, there are currently 8 groups in my system.
Now, let us find out which groups my user, for example sk, belongs to. To do so, enter:
$ groups sk wheel network audio optical storage power vboxusers users
Here, sk is my username and the user sk is the member of all of the above groups.
We can also find the list of users that belongs to a specific group. For instance, the following command displays the users which are belongs to the group named storage.
$ grep -w storage /etc/group storage:x:95:sk
Easy, right? Indeed. Finding which groups a user belongs and the users of a specific group is super easy!! For more details about groups command, refer man pages.
$ man groups
And, that’s all for now. Hopes this helps. If you find this guide useful, please spend a moment to share it on your social, professional networks and support OSTechNix.
More good stuffs to come. Stay tuned!