Get the App
SLTechnology News&Howtos  ›  Servers  › 

Teach you to play Linux- user group management.

Shulou Source: shulou.com Published: 2022-06-02 07:02:21 10月01日 Update

Each user has a user group, and the system can centrally manage all users in a user group. Different Linux systems have different rules for user groups, for example, users under Linux belong to a user group with the same name, which is created at the same time as the user is created.

The management of user groups involves the addition, deletion and modification of user groups. Group additions, deletions, and modifications are actually updates to the / etc/group file.

1. Add a new user group to use the groupadd command. The format is as follows: groupadd option user group

The options you can use are:

-g GID specifies the group identification number (GID) of the new user group.

-o is generally used in conjunction with the-g option to indicate that the GID of a new user group can be the same as the GID of an existing user group on the system.

Example 1:

# groupadd group1

This command adds a new group group1 to the system, and the group identification number of the new group is added 1 to the current largest group identification number.

Example 2:

# groupadd-g 101 group2

This command adds a new group group2 to the system and specifies that the group identification number of the new group is 101.

2. If you want to delete an existing user group, use the groupdel command in the following format: groupdel user group

For example:

# groupdel group1

This command removes the group group1 from the system.

3. Use the groupmod command to modify the attributes of a user group. The syntax is as follows: groupmod option user group

Common options are:

-g GID specifies a new group identification number for the user group.

Using the-o option with the-g option, the new GID of the user group can be the same as the GID of the existing user group of the system.

-n New user group changes the name of the user group to a new name

Example 1:

# groupmod-g 102 group2

This command changes the group identification number of the group group2 to 102.

Example 2:

# groupmod-g 10000-n group3 group2

This command changes the identification number of the group group2 to 10000 and the group name to group3.

4. If a user belongs to multiple user groups at the same time, the user can switch between user groups in order to have the permissions of other user groups.

After logging in, the user can switch to another user group using the command newgrp, whose parameter is the destination user group. For example:

$newgrp root

This command switches the current user to the root user group, provided that the root user group is indeed the primary or additional group of the user. Similar to the management of user accounts, the management of user groups can also be accomplished through integrated system management tools.

Original address: https://www.linuxprobe.com/user-group-management.html

Tags: User user group command system identity identification number management at the same time instance switch different same name namely format maximum between premise original text parameter Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Apple Redmi Linux