5.2 Managing Groups Using CLI

To give rights to individual users is a lot of work, so administrators tend to devide users into groups to create a system called “Role Based Access abreviated”, or RBAC.

Adding groups and setting passwords

This will teach you how to create groups and add users to these groups.

We want to add the group suicidesquad with the members Romeo and Juliet

And add the group deadgreeks with the members Plato and Aristotle

Let’s become root for this exersise.

su - root

Let’s add the group suicidesquad with a group id of 30000 to the machine.

groupadd -g 30000 suicidesquad

Let’s create the group deadgreeks to the machine

groupadd deadgreeks

Check if the groups exist:

[root@rhcsa ~]# tail -3 /etc/group
aristotle:x:1006:
suicidesquad:x:30000:
deadgreeks:x:30001:

The groups where added at the bottom of the /etc/group file. This file stores all the groups. Also, see that the group id or GID has been set and that the next added group followed the highest number.

Add users to groups

Now we must add the users to their respective groups and their final fate.

usermod -G suicidesquad juliet

The capital G adds the user to the group, but as their secondary group. This will not replace the primairy group and therefore Juliet is still part of the group. Juliet and the group suicidesquad membership were added. You can check this with the id command.

id juliet
[root@rhcsa ~]# id juliet
uid=1003(juliet) gid=1003(juliet) groups=1003(juliet),30000(suicidesquad)

And check the /etc/group file.

tail -3 /etc/group
[root@rhcsa ~]# tail -3 /etc/group
aristotle:x:1006:
suicidesquad:x:30000:juliet
deadgreeks:x:30001:

Practice Question

Now do the following on your own and check your results. This simulates a question on the Red Hat exam.

Add the following users to their groups.

To suicidesquad

  • Romeo

To deadgreeks

  • Plato

  • Aristotle

  • Theireconomy