Linux user group management - add a new user group

Linux user group management - add a new user group

In Linux systems, user groups are a means of managing and assigning permissions to system resources. This article will introduce how to add a new user group in the Linux system, including syntax, practical operation, and the differences between adding new user groups.

1. Grammar

Use groupaddthe command to add a new user group in the Linux system, and its basic syntax is:

groupadd [选项] 用户组

Available options are:

  • -g GID: Specifies the group identification number (GID) of the new user group.
  • -o: Generally -gused together with the option, indicating that the GID of the new user group can be the same as the GID of the existing user group in the system.

2. Practical operation

The following are the specific steps to add a new user group in the Linux system:

  1. Open a terminal window and log in as an administrator.

  2. Enter the following command to add a new user group:

    sudo groupadd [选项] 用户组
    
  3. Add appropriate options as needed, for example:

    sudo groupadd -g 1000 testgroup
    

    This command will create a testgroupnew group named and set its GID to 1000.

  4. Use /etc/groupthe file to see if the newly created user group has been added successfully.

3. The difference between adding a new user group

In the Linux system, there are many ways to add a new user group. The following briefly introduces three of them:

3.1 Use groupaddcommand to add a new user group

groupaddThe command is one of the most commonly used commands to add a new user group in the Linux system. This command can use -gthe parameter to specify the GID of the new user group, or use -othe parameter to indicate that the GID of the new user group can be the same as the GID of the existing user group in the system.

3.2 Use /etc/groupthe file to manually add a new user group

Another way is to directly modify /etc/groupthe file to manually add a new user group. Find an unused GID in that file, and add a line similar to the following at the end of the file:

newgroup:x:GID:

Among them, newgroupis the name of the newly created user group, GIDand is the GID of the newly created user group.

3.3 Use addgroupthe command to add a new user group

addgroupThe command is a high-level tool that automatically assigns an unused GID when adding a new user group. It also provides more options, such as adding description information for new groups, etc.

in conclusion

The above is the method of adding a new user group in the Linux system, including the groupaddbasic syntax of commands, practical operations, and the differences between adding new user groups. When doing Linux system administration, it is very important to choose the appropriate method to add new user groups according to the specific situation.

おすすめ

転載: blog.csdn.net/m0_67268191/article/details/130854312