This brief tutorial shows students and new users how to list groups on Ubuntu 18.04 | 16.04 Linux systems.
Listing user groups on Ubuntu Linux is essential for system administration tasks. It allows you to see which users can access specific resources and helps you manage permissions and access control for your system.
As a beginner, learning how to list user groups is an excellent introduction to Linux user management, and it will help you understand Linux file permissions and ownership.
Overall, understanding user groups is a fundamental part of Linux system administration and a skill that every Linux user should know.
Linux Groups:
There are two types of groups users can be assigned to. One is a primary, and the other is a second group that grants privileges to users to access specific resources.
Below is how a typical Linux user account is added and assigned group memberships:
User — A user with an account must belong to one primary group. The user’s primary group is typically named after the user account name.
Primary Group — The primary group is created simultaneously when the user account is created, and the user is automatically added to it. The file created by the user automatically belongs to the user group.
Secondary Group — This group is not required and is only there to give users access to other resources they don’t already have access to. Users can belong to one or as many secondary groups as possible.
The primary user’s group is stored in the /etc/passwd file, and the supplementary groups, if any, are listed in the /etc/group file.
List User Groups using the group’s command
Now that you know the types of groups for users, you can use the groups command to find the groups to which a user belongs. Running the groups command without arguments will list all the groups to which the user belongs.
Example:
groups
Should output all the groups the account richard belongs to. The primary group is the first group with the same name as the user account name.
Ouput: richard adm cdrom sudo dip plugdev lpadmin sambashare
To list all the groups a user belongs, add the username to the group’s command
example:
groups richard
This should output the same as above
Output richard : richard adm cdrom sudo dip plugdev lpadmin sambashare
List User Groups using the id command
One can also use the id command to list group information about the specified user. It prints user and group information for the specified USER,
The command will show the username (uid), the user’s primary group (gid), and the user’s secondary groups (groups)
id richard
Should output the line below:
Output: uid=1000(richard) gid=1000(richard) groups=1000(richard),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare)
List Group Membership using the getent command
If you want to know a particular group’s members, use the getent command. This command gets entries from the administrative database.
To get a membership of the cdrom group, run the command below
getent group cdrom
This should output all the users who have access to the cdrom group.
Listing All Groups
To list the entire groups on Ubuntu, run the command below
less /etc/group
That should output all the groups on each line
root:x:0: daemon:x:1: bin:x:2: sys:x:3: adm:x:4:syslog,richard tty:x:5: disk:x:6: lp:x:7: mail:x:8: news:x:9: uucp:x:10: man:x:12: proxy:x:13: kmem:x:15: dialout:x:20: fax:x:21: voice:x:22: cdrom:x:24:richard floppy:x:25: tape:x:26: sudo:x:27:richard audio:x:29:pulse dip:x:30:richard .
That’s it
Congratulations! You have learned how to list groups on Ubuntu Linux.
Leave a Reply Cancel reply