YouTube Icon

Code Playground.

How to Create Groups in Linux (groupadd Command)

CFG

How to Create Groups in Linux (groupadd Command)

In Linux, bunches are utilized to arrange and control client accounts. The basic role of gatherings is to characterize a bunch of advantages, for example, perusing, composing, or executing consent for a given asset that can be shared among the clients inside the gathering. 

In this article, we will discuss how to make new gatherings in Linux, utilizing the groupadd order. 

groupadd Command Syntax

The overall linguistic structure for the groupadd order is as per the following: 

groupadd [OPTIONS] GROUPNAME

Just the root or a client with sudo advantages can make new gatherings. 

When conjured, groupadd makes another gathering utilizing the alternatives indicated on the order line in addition to the default esteems determined in the/and so forth/login.defs record. 

Creating a Group in Linux

To make another gathering type groupadd followed by the new gathering name. 

For instance, to make another gathering named mygroup you would run: 

groupadd mygroup

The order adds a section for the new gathering to the/and so forth/gathering and/and so on/gshadow documents. 

When the gathering is made, you can begin adding clients to the gathering . 

On the off chance that the gathering with a similar name as of now exist, the framework will print a mistake message like the accompanying: 

groupadd: group 'mygroup' already exists

To stifle the mistake message if the gathering exist and to make the order exit effectively, utilize the - f (- - power) alternative: 

groupadd -f mygroup

Creating a Group with Specific GID

In Linux and Unix-like working frameworks, bunches are recognized by its name and a novel GID (a positive whole number). 

Naturally, when another gathering is made, the framework allots the following accessible GID from the scope of gathering IDs indicated in the login.defs document. 

Utilize the - g (- - gid) choice to make a gathering with a particular GID. 

For instance to make a gathering named mygroup with GID of 1010 you would type: 

groupadd -g 1010 mygroup

You can confirm the gathering's GID, by posting all gatherings and sifting the outcome with grep : 

getent group | grep mygroup
mygroup:x:1010:

In the event that a gathering with the given GID as of now exist, you will get the accompanying mistake: 

groupadd: GID '1010' already exists

At the point when utilized with the - o (- - non-interesting) choice the groupadd order permits you to make a gathering with non-remarkable GID: 

groupadd -o -g 1010 mygroup

Creating a System Group

There is no genuine specialized distinction between the framework and customary (ordinary) gatherings. As a rule, framework bunches are utilized for some exceptional framework activity purposes, such as making reinforcements or doing framework support. 

Framework bunches GIDs are browsed the scope of framework bunch UDs determined in the login.defs record, which is not the same as the reach utilized for customary gatherings. 

Utilize the - r (- - framework) alternative to make a framework gathering. For instance, to make another framework bunch named mysystemgroup you would run: 

groupadd -r mysystemgroup

Overriding the Default /etc/login.defs Values

The - K (- - key) alternative followed by KEY=VAL permits you to supersede the default esteems determined in the/and so forth/login.defs record. 

Fundamentally, everything you can abrogate are the most extreme and least estimations of the ordinary and framework bunch IDs for programmed GID choice while making another gathering. 

Suppose you need to make another gathering with GID in the reach somewhere in the range of 1200 and 1500. To do that, determine the min/max esteems as demonstrated as follows: 

groupadd -K GID_MIN=1200 -K GID_MAX=1500 mygroup

Creating a System Group with Password

Adding a secret key to a gathering has no commonsense use and may cause a security issue since more than one client should know the secret key. 

The - p (- - secret word) choice followed by secret word permits you to set a secret phrase for the new gathering: 

groupadd -p grouppassword mygroup

Conclusion

In Linux, you can make new gatherings utilizing the groupadd order. 

Similar guidelines apply for any Linux circulation, including Ubuntu, CentOS, RHEL, Debian, Fedora, and Arch Linux. 

Don't hesitate to leave a remark in the event that you have any inquiries.




CFG