search
HomeOperation and MaintenanceLinux Operation and MaintenanceWhat does it mean to create a group in Linux?

In Linux, establishing a group means "creating a user group", which can be achieved using the groupadd command. The groupadd command is used to create a new user group. The information of the new user group will be added to the system file. The syntax is "groupadd [options] groupname"; the parameter "options" is the parameter used by the groupadd command, and "groupname" is required. The name of the added user group.

What does it mean to create a group in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

In Linux, establishing a group means "creating a user group". The user group configuration file is "/ect/group". All information about the user group is stored in this file; this file is a file corresponding to the group ID (GID) and group name. As mentioned before, the fourth field of each line of user information in the etc/passwd file records the user's initial group ID. So, what is the group name of this GID? Just look for it in the /etc/group file.

What is the user group of Linux

Linux is a multi-user, multi-tasking time-sharing operating system. If you want to use system resources, just You must apply for an account from the system administrator and then enter the system through this account. This account and user are the same concept. By establishing users with different attributes, on the one hand, system resources can be reasonably utilized and controlled. On the other hand, it can also help users organize files and provide security protection for user files.

Each user uses a unique username and password. When logging in to the system, only if the username and password are entered correctly can the system and their own home directory be entered.

A user group is a logical collection of users with the same characteristics. Sometimes we need to allow multiple users to have the same permissions.

For example, to view and modify the permissions of a certain file, one method is to authorize file access to multiple users respectively. If there are 10 users, they need to authorize 10 times. Obviously, this method is not reasonable. .

Another method is to create a group, give this group the permission to view and modify this file, and then put all users who need to access this file into this group, then all users will have the permissions and group Same permissions. This is a user group. Grouping users is a means of managing users and controlling access rights in the Linux system. By defining user groups, management work is simplified to a great extent.

To put it bluntly, a user group is a technical means for unified management of the same type of objects in Linux. It puts the same type of users into a group and encapsulates them into a larger whole;

It's like encapsulating the same type of students into a class, the students are the users, and the class is the group; operating on the class is actually operating on all students in the class;

Relationship between users and groups

The corresponding relationships between users and user groups are: one-to-one, one-to-many, many-to-one and many-to-many; the following figure shows this relationship:

  • One-to-one: That is, a user can exist in a group or be the only member of the group.

  • One-to-many: that is, one user can exist in multiple user groups. Then this user has common permissions for multiple groups.

  • Many-to-one: Multiple users can exist in a group, and these users have the same permissions as the group.

  • Many-to-many: Multiple users can exist in multiple groups. In fact, it is an expansion of the above three corresponding relationships.

Linux groupadd command detailed explanation

The groupadd command is used to create a new user group and the information of the new user group will be added to the system files.

Syntax

groupadd [options] groupname

Parameters

Parameters Description
#options Options used by the groupadd command.
groupname The user group name to be added.

Common options for the groupadd command

Options Meaning
-g Specify the id of the new user group.
-r Create a system user group whose group ID is less than 500.
-K Overwrite the configuration file "/ect/login.defs".
-o Allows adding user groups with non-unique group IDs.
-f,–force This option will fail only to exit with a success status if the specified group already exists. When used with -g, and the specified GID_MIN already exists, selects another unique GID (i.e. -g is turned off).

说明

创建用户组之后,会修改如下几个文件:

文件 描述
/etc/group 组账户信息。
/etc/gshadow 安全组账户信息。
/etc/login.defs Shadow 密码套件配置。

Linux groupadd命令常用实例

实例

实例 描述
groupadd groupname 创建用户组 groupname
groupadd -g groupid groupname 创建用户组 groupname,并指定组 id 为 groupid

创建用户组

使用 groupadd 命令,新建一个用户组 haicoder,具体命令如下:

groupadd haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

此时,用户组 haicoder 已经添加成功了,现在,我们使用 cat 和 grep 命令,查看用户组相关文件,具体命令如下:

cat /etc/group | grep haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

我们看到,用户组文件中,已经添加了该用户组,测试完毕后,我们使用 groupdel 命令,删除用户组,具体命令如下:

groupdel haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

即,我们成功删除了用户组 haicoder。

创建用户组并指定组id

我们使用 groupadd 命令,新建一个用户组 haicoder 并指定组 id 为 320,具体命令如下:

groupadd -g 320 haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

此时,用户组 haicoder 已经添加成功了并且,我们设置了其组 id 为 320,现在,我们使用 cat 和 grep 命令,查看用户组相关文件,具体命令如下:

cat /etc/group | grep haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

我们看到,用户组文件中,已经添加了该用户组并且其组 id 为 320,测试完毕后,我们使用 groupdel 命令,删除用户组,具体命令如下:

groupdel haicoder

运行后,终端输出如下:

What does it mean to create a group in Linux?

即,我们成功删除了用户组 haicoder。

相关推荐:《Linux视频教程

The above is the detailed content of What does it mean to create a group in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Linux Operations: Utilizing the Maintenance ModeLinux Operations: Utilizing the Maintenance ModeApr 19, 2025 am 12:08 AM

Linux maintenance mode can be entered through the GRUB menu. The specific steps are: 1) Select the kernel in the GRUB menu and press 'e' to edit, 2) Add 'single' or '1' at the end of the 'linux' line, 3) Press Ctrl X to start. Maintenance mode provides a secure environment for tasks such as system repair, password reset and system upgrade.

Linux: How to Enter Recovery Mode (and Maintenance)Linux: How to Enter Recovery Mode (and Maintenance)Apr 18, 2025 am 12:05 AM

The steps to enter Linux recovery mode are: 1. Restart the system and press the specific key to enter the GRUB menu; 2. Select the option with (recoverymode); 3. Select the operation in the recovery mode menu, such as fsck or root. Recovery mode allows you to start the system in single-user mode, perform file system checks and repairs, edit configuration files, and other operations to help solve system problems.

Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment