Create a Group in Linux CLI

Creating a group in Linux command line interface (CLI) can be a bit tricky if you’re not familiar with the process. But once you know how to do it, it’s a breeze. In this article, we’ll walk you through the steps of creating a group in Linux CLI, and provide some examples to help you understand the process better.

What is a Group in Linux?

Before we dive into the process of creating a group, let’s first understand what a group is in Linux. A group is a collection of users that have similar access rights and permissions to resources on a Linux system. For example, if you have a group of users that need access to a specific folder on your system, you can create a group and assign those users to that group. This way, you can easily manage the permissions for that group and ensure that only the intended users have access to that folder.

Creating a Group in Linux CLI

To create a group in Linux CLI, you’ll need to use the groupadd command. This command is used to add new groups to the system. The basic syntax for the groupadd command is as follows:

groupadd [options] groupname

Where groupname is the name of the group you want to create. Here are some examples of how to use the groupadd command:

Creating a Group with a Specific GID

In this example, we’ll create a group called “marketing” with a GID (Group ID) of 1000. The GID is a unique numerical identifier assigned to each group on a Linux system.

groupadd -g 1000 marketing

Creating a Group with a Description

In this example, we’ll create a group called “sales” with a description of “Sales Team”.

groupadd -c "Sales Team" sales

Creating a Group with a System User

In this example, we’ll create a group called “admin” and assign it as a system user. System users are users that are created for specific system tasks and are not intended for login.

groupadd -r admin

Managing Group Members

Once you’ve created a group, you’ll need to add users to that group. This can be done using the usermod command. The basic syntax for the usermod command is as follows:

usermod -a -G groupname username

Where groupname is the name of the group you want to add the user to, and username is the name of the user you want to add to the group. Here’s an example of how to use the usermod command:

Adding a User to a Group

In this example, we’ll add the user “jane” to the group “marketing”.

usermod -a -G marketing jane

Removing a User from a Group

In this example, we’ll remove the user “john” from the group “sales”.

gpasswd -d john sales

Managing Group Permissions

Once you’ve created a group and added users to that group, you’ll need to set the permissions for that group. This can be done using the chmod command. The basic syntax for the chmod command is as follows:

chmod [permissions] [path]

Where permissions are the permissions you want to set for the group, and path is the location of the file or folder you want to set the permissions for. Here’s an example of how to use the chmod command:

Setting Permissions for a Folder

In this example, we’ll set permissions for the folder “marketing_files” so that the group “marketing” has read and execute permissions.

chmod 750 /marketing_files

This command sets the permissions for the “marketing_files” folder so that the owner (user) has read, write, and execute permissions, while the group “marketing” has read and execute permissions, and others have no permissions.

Setting Permissions for a File

In this example, we’ll set permissions for the file “sales_report.txt” so that the group “sales” has read and write permissions.

chmod 660 /sales_report.txt

This command sets the permissions for the “sales_report.txt” file so that the owner (user) and the group “sales” have read and write permissions, and others have no permissions.

Conclusion

Creating a group in Linux CLI can be a bit tricky at first, but once you understand the process, it’s a breeze. The groupadd command is used to create new groups, while the usermod command is used to add users to a group. The chmod command is used to set the permissions for a group. By following the examples and steps outlined in this article, you’ll be able to create a group, add users to that group, and set the permissions for that group in no time.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

nineteen − 1 =

Related Articles