Home Operation and Maintenance Linux Operation and Maintenance What does it mean to create a group in Linux?

What does it mean to create a group in Linux?

Nov 11, 2022 pm 03:06 PM
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
Copy after login

Parameters

ParametersDescription
#optionsOptions used by the groupadd command.
groupnameThe user group name to be added.

Common options for the groupadd command

OptionsMeaning
-gSpecify the id of the new user group.
-rCreate a system user group whose group ID is less than 500.
-KOverwrite the configuration file "/ect/login.defs".
-oAllows adding user groups with non-unique group IDs.
-f,–forceThis 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.defsShadow 密码套件配置。

Linux groupadd命令常用实例

实例

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

创建用户组

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

groupadd haicoder
Copy after login

运行后,终端输出如下:

What does it mean to create a group in Linux?

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

cat /etc/group | grep haicoder
Copy after login
Copy after login

运行后,终端输出如下:

What does it mean to create a group in Linux?

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

groupdel haicoder
Copy after login
Copy after login

运行后,终端输出如下:

What does it mean to create a group in Linux?

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

创建用户组并指定组id

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

groupadd -g 320 haicoder
Copy after login

运行后,终端输出如下:

What does it mean to create a group in Linux?

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

cat /etc/group | grep haicoder
Copy after login
Copy after login

运行后,终端输出如下:

What does it mean to create a group in Linux?

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

groupdel haicoder
Copy after login
Copy after login

运行后,终端输出如下:

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 of this Website
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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.

See all articles