Add user to a Group in AlmaLinux/Ubuntu/Linux Mint

In this article, we cover how to add user to a group in AlmaLinux/Ubuntu/Linux Mint. If there are multiple users accessing the same machine. Then, a System Administrator would have to manage each of those users. So, only authorized users are allowed to access specific system resources.

Let’s say we have a group of 4 users working on a project. And, we can’t let other users to access files of that project. Therefore, we can create a group of 4 users and set file permissions in a manner that doesn’t let other users access those files.

Users and Groups

Users are part of groups. Every user is a part of at least one group. And, each user in a group is allowed to perform certain common tasks. So, what we do here is – create a group, make a user part of it. Assign permissions to the group itself. And, we are good to go.

That way, we don’t have to assign permissions for individual users. Clearly, an efficient outcome.

When a user is created, it also creates a group with the same name. For instance, if a new user XYZ is created then, at the same time a new group with XYZ will also be created. And, user XYZ becomes a part of group XYZ.

/etc/group contains the list of groups a user is part of. To identify which group a user belongs to, use groups command-line utility. For instance,

$ groups user_name

Add user to a group in AlmaLinux/Ubuntu/Linux Mint

Note: Following operations require administrative rights, contact your System Administrator if you don’t have superuser access.

First, create two groups – primary and secondary.

# groupadd <primarygrp-name>
# groupadd <secondarygrp-name>

Now, with the help of a usermod command, we can add user to a group (change its primary group and add to a secondary group) –

To change a users’ primary group –

# usermod -g <primarygrp-name> <username>

To add a user to secondary group –

# usermod -G <secondarygrp-name> <username>

-g option is for the user’s primary group and -G for its secondary group. Verify it with command –

$ groups username

In conclusion, we have discussed the command line tools available to add user to a group in AlmaLinux, Ubuntu and Linux Mint.

Similar Posts