What does it mean to create a group in Linux?

青灯夜游
Release: 2022-11-11 15:06:40
Original
3419 people have browsed it

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

运行后,终端输出如下:

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

运行后,终端输出如下:

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!