As an administrator, adding a user to the group is also beneficial to maintain security. However, if you are unfamiliar with how to add users to a group, we recommend you to read this guide completely. In this guide, we will explain the simple methods to add the users to a group in Rocky Linux 9 (RHEL-based OS).
In Rocky Linux, there are multiple ways to add the users to a group. But if you want to create a group first, run the following command:
Make sure that you replace the “group” with the name that you want to use. For example, we create a group named “LinuxTeam”:
If you want to list all the available groups in the system, you can run the following command:
As you can see in the previous image, there are 5 groups: LinuxTeam, LinuxTeam_Devs, LinuxTeam_Managers, LinuxTeam_Interns, and LinuxTeam_SEO. If you want to get a simplified result, execute this command:
Now, we have multiple users in the system. Let’s list them all through the following command:
If you want to add a user to a group, run the following command:
In the previous command, the -a option ensures that the users must be added to a group without removing them from the existing one.
Similarly, you can use the “gpasswd” command to manage the groups’ passwords and memberships. Here is the example command that you can try:
If you want to add a single user in multiple groups, you can run the following command:
sudo usermod -a -G <group1>,<group2>,<group3> <username>
If you want to remove a user from a group, run the following command:
This tutorial is all about adding a user to a group in Rocky Linux 9. This guide works like a complete information to understand everything about adding and removing groups in Linux. Remember to use the previous commands correctly. Otherwise, you may get errors while adding users to groups.