[wpseo_breadcrumb]

Create a Group in Linux CLI

Update on:
Jan 19, 2023

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.

Related Posts

Upgrading system Off-line with ISO and Yum

Upgrading a system can be a daunting task, especially if it is an off-line system. An off-line system is one that is not connected to the internet and cannot access online resources. The good news is that you can still upgrade your system even when it is not connected...

Configuring Yum

Introduction Yum (Yellowdog Updater, Modified) is a package manager for Red Hat based Linux distributions, including Fedora and CentOS. It helps in managing and updating the software packages on the system, including their dependencies and conflicts. In this article,...

Yum Commands and Options

Introduction Yum is a package manager used in Red Hat-based systems like Fedora, CentOS, and Red Hat Enterprise Linux. With Yum, users can easily install, update, and remove packages from the terminal. In this article, we'll explore the basic Yum commands and their...

Setting up a YUM Repository

Introduction YUM (Yellowdog Updater, Modified) is a popular open-source package management system used to install, update, and remove packages in Linux distributions such as Fedora, Red Hat Enterprise Linux (RHEL), and CentOS. YUM makes it easier to manage packages by...

Follow Us

Our Communities

More on Linux

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published.

1 × 1 =