Creating and adding a new user to a group in Linux

Groups can be used to set privileges on users, privileges like running applications, reading, or writing in directories.

Groups in Linux act as organization blocks that are used to sort and govern Linux user accounts. Groups can be used to set privileges on users, privileges like running applications, reading, or writing in directories.

There are two types of groups namely, Primary groups and Secondary groups. Primary groups are created when a Linux user creates a new file. Typically the group name is similar to the user who created the file. However, Secondary groups are used when you need to give a group of users specific permission on a file. Every Linux user must belong to only one primary group and none or more than one secondary group.

After following the guide, you shall be able to create a group and assign users to it. We shall also provide you some tips on Linux groups.

This tutorial was tested on Ubuntu, but the commands should work on all Linux distributions.

Adding Users to a Group in Linux

Linux Groups examples on Ubuntu

Example 1. To add a new group.

sudo groupadd fosslinuxgrp

Add New Group
Add New Group

Example 2. To add an existing user to an existing group.

sudo usermod -a -G fosslinuxgrp hendadel

Add Existing User To Existing Group
Add Existing User To Existing Group

Example 3. To change the primary group for an existing user.

sudo usermod -g fosslinuxgrp hendadel

Note that the “-g” option is to assign a primary group while the “-G” option from the previous example s to assign a secondary group.

Change Primary Group For Existing User
Change Primary Group For Existing User

Example 4. List all the assigned groups to the current logged in user.

groups

Display Groups of the Current User
Display Groups of the Current User

Example 5. To display all the assigned groups for a specific user.

groups hendadel

Display Groups of User
Display Groups of User

Example 6. To create a new user and assign an existing group to it.

sudo useradd -G fosslinuxgrp celine

This command creates a new user called “celine” and assigns it to an already existing group, which is “fosslinuxgrp.”

Create A New User and Add to Existing Group
Create A New User and Add to Existing Group

But do not forget to assign a password to the newly created user using the below command:

sudo passwd celine

Assign Password To New User
Assign Password To New User

Example 7. Add an existing user to multiple groups.

sudo usermod -a -G fosslinuxgrp,backup celine

Add Existing User to Multiple Groups
Add Existing User to Multiple Groups

Example 8. To display all the groups that are found on the Linux system, you can use the  command as follows:

getent group

Display All Groups in The System
Display All Groups in The System

That’s all about adding users to groups on Linux. I hope you enjoyed it.

Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

22,995FansLike
407FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

The fight for dominance in the Linux desktop environments has mostly been a tug of war between GNOME and KDE. It is difficult to portray a winner in this tug of war. The user community influence and its user preference determine which Linux desktop environment to choose as an adaptive platform. This presumed stalemate in the Linux desktop arena portrays KDE and GNOME as the main major players.
Photo editing is a global hobby, profession, and exploit. Its execution is not dependant on a specific Operating System or device. For this reason, anyone can be a photo editor regardless of their Operating system preference. The power of an ideal and reliable photo editor is in the many unique features they present to their users. Some features pose unique photo editing benefits like correcting brightness imbalances and color hue. Some editors are efficient in sharpness adjustments and red-eye removal. Others present flexible auto-cropping and zoom features. These are some of the characteristics that define a photo editor.