{"id":3804,"date":"2021-01-25T18:11:33","date_gmt":"2021-01-25T18:11:33","guid":{"rendered":"https:\/\/linuxways.net\/?p=3804"},"modified":"2021-01-25T18:14:22","modified_gmt":"2021-01-25T18:14:22","slug":"how-to-find-out-which-groups-a-user-belongs-to-in-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-find-out-which-groups-a-user-belongs-to-in-ubuntu-20-04\/","title":{"rendered":"How to Find out Which Groups a User Belongs to in Ubuntu 20.04"},"content":{"rendered":"<p>A group is a collection of user accounts that have the same set of permission and access rights on the files, folders, and configurations. When a new user is created in Linux OS, it is automatically added to a group with the same name as the user. A single user can be a part of single or multiple groups.<\/p>\n<p>Sometimes, we need to find out which groups a user belongs to. It helps to understand what type of permissions users have and troubleshoot when things are not working properly. In this post, we will show how to find out which groups a user belongs to in Ubuntu.<\/p>\n<p><strong>Note<\/strong>: The commands mentioned here have been tested on <strong>Ubuntu 20.04 LTS<\/strong>. These commands also applies for other Linux distributions.<\/p>\n<h2>How to Find Which Groups a Linux User Belongs To<\/h2>\n<p>First, open the Terminal by pressing the Ctrl+Alt+T shortcut. Then in order to check the groups the current user account belongs to, type <em>groups<\/em> in the Terminal and press Enter:<\/p>\n<pre>$ groups<\/pre>\n<p>It will show the groups to which the currently logged-in user belongs to. For example, the following output is showing the name of the groups to which the currently logged-in user &#8220;kbuzdar\u201d is a member of. <img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"66\" class=\"wp-image-3805\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/groups-command.png\" alt=\"groups command\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/groups-command.png 618w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/groups-command-300x32.png 300w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/p>\n<p>To find groups information for a specific user other than the current logged in user, type <em>groups<\/em> followed by that username:<\/p>\n<pre>$ groups &lt;user_name&gt;<\/pre>\n<p>For example, to find which groups a user named \u201ctest\u201d belongs to, the command would be:<\/p>\n<pre>$ groups test<\/pre>\n<p>Alternatively, you can also use the <strong>id<\/strong> command to find out which groups a current logged in user belongs to:<\/p>\n<pre>$ id<\/pre>\n<p>It will show all the groups along with their group IDs to which the currently logged-in user belongs to.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"831\" height=\"85\" class=\"wp-image-3806\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/id-command.png\" alt=\"id command\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/id-command.png 831w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/id-command-300x31.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/id-command-768x79.png 768w\" sizes=\"auto, (max-width: 831px) 100vw, 831px\" \/><\/p>\n<p>To find groups information for a user other than the current logged in user, type <em>id<\/em> followed by the username:<\/p>\n<pre>$ id &lt;user_name&gt;<\/pre>\n<h3>List All Groups in Linux<\/h3>\n<p>If you want to list all groups that exist in your system, issue the following command in Terminal:<\/p>\n<pre>$ cat \/etc\/group<\/pre>\n<p>This command will list all the groups that exist in your system.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"435\" class=\"wp-image-3807\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-all-groups.png\" alt=\"listing all groups\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-all-groups.png 343w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-all-groups-237x300.png 237w\" sizes=\"auto, (max-width: 343px) 100vw, 343px\" \/><\/p>\n<p>Likewise listing all groups, you can also <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-list-users-in-linux\/\">list all users<\/a> on your system.<\/p>\n<h3>List All Members of a Group<\/h3>\n<p>If you want to list all members of a group, issue the following command in the Terminal:<\/p>\n<pre>$ getent group &lt;group_name&gt;<\/pre>\n<p>This command will print the group name followed by all its members. For example, to print all the members of the \u201csudo\u201d group, the command would be:<\/p>\n<pre>$ getent group sudo<\/pre>\n<p>The following output shows the \u201csudo\u201d group has two members: \u201ckbuzdar\u201d and \u201cummara\u201d.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"426\" height=\"65\" class=\"wp-image-3808\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-members-of-group.png\" alt=\"listing members of group\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-members-of-group.png 426w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/listing-members-of-group-300x46.png 300w\" sizes=\"auto, (max-width: 426px) 100vw, 426px\" \/><\/p>\n<h2>Bonus:<\/h2>\n<h3>Adding User in a Group<\/h3>\n<p>If you want to add a user to a group, use the following command syntax:<\/p>\n<pre>$ sudo usermod -aG &lt;group_name&gt; &lt;user_name&gt;<\/pre>\n<p>For instance, to add an already existing user \u201cummara\u201d to the \u201csudo\u201d group, the command would be:<\/p>\n<pre>$ sudo usermod -aG sudo ummara<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"64\" class=\"wp-image-3809\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/add-user-in-group.png\" alt=\"add user in group\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/add-user-in-group.png 557w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/add-user-in-group-300x34.png 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/p>\n<h3>Removing User from a Group<\/h3>\n<p>To remove a user from a group, use the following command syntax:<\/p>\n<pre>$ sudo gpasswd -d &lt;user_name&gt; &lt;group_name&gt;<\/pre>\n<p>For instance, to remove the user \u201cummara\u201d from the \u201csudo\u201d group, the command would be:<\/p>\n<pre>$ sudo gpasswd -d ummara sudo<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"475\" height=\"83\" class=\"wp-image-3810\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/remove-user-from-group.png\" alt=\"remove user from group\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/remove-user-from-group.png 475w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/01\/remove-user-from-group-300x52.png 300w\" sizes=\"auto, (max-width: 475px) 100vw, 475px\" \/><\/p>\n<p>By following the procedure shared in this post, you can easily find out which groups a user belongs to in Ubuntu. We have also shared how to list all groups in a system, list members of a group, add and remove a user from the group. For information about adding\/removing users in a system, visit our post on <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-add-and-remove-users-on-ubuntu-20-04\/\">how to add and remove users on Ubuntu<\/a>.<\/p>\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>A group is a collection of user accounts that have the same set of permission and access rights on the files, folders, and configurations. When a new user&hellip;<\/p>","protected":false},"author":4,"featured_media":3813,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[154,100,155],"class_list":["post-3804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-groups","tag-ubuntu-20-04","tag-user"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=3804"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/3804\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/3813"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=3804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=3804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=3804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}