How to List All User Groups on Ubuntu 18.04 | 16.04 with Examples

This brief tutorial shows students and new users how to list groups on Ubuntu 18.04 | 16.04 Linux systems..

If you’re a student or new user looking for a Linux system to start learning on, the easiest place to start is on Ubuntu Linux OS…. It’s a great Linux operating system for beginners..

Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices…

Students and new users will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to use the system to get work done.…

Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses..

However, when you’re learning to use and understand Ubuntu Linux, you should also learn how to use the command line to terminal.. Most Linux users can do some basic command line tasks.. This tutorial is going to show you how…..

This post shows you how to perform a basic task of listing groups on Ubuntu Linux…

When you’re ready to learn how to list groups on Ubuntu, follow the steps below:

Linux Groups:

There are two types of groups users can be assigned to: One is a primary and the other a secondary group which grants privileges to user to access certain resources..

Below is how a typical Linux user account is added and assigned group memberships:


User  — A user has an account must belong to one primary group. Typically the the user’s primary group is also named after the user account name..
Primary Group  — The primary group is created at the same time the user account is created and the user is automatically added to it.. File created by the user automatically belongs to the user group..
Secondary Group  — This group is not required and only there to give users access to other resources they’re don’t already have access to.. Users can belong to none or as many secondary groups are 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 groups command

Now that you know the types of groups for users, you can use the groups command to find the groups a user belongs to.. Running the groups command without any arguments, will list all the groups the user belongs to..

example:

groups

Should output all the group the account richard belongs to. The first group with same name as the user account name is the primary group.

Ouput:
richard adm cdrom sudo dip plugdev lpadmin sambashare

To list all the groups a user belongs, add the username to the groups command

example:

groups richard

This should output 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 groups information about 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 who are members of a particular group, use the getent command.. This command gets entries from 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.

You may also like the commands below:

A Brief Introduction to the vi Text Editor on Ubuntu 18.04 with Examples

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.