Introduction to how users add to groups under Linux

Source: Internet
Author: User

When the Linux system adds users to groups (group), use the gpasswd-a or USERMOD-AG commands.

Several ways to add users to a group

When creating a user, there are several ways to add users to a specified group.

The code is as follows Copy Code

(1) Specify group when creating user

# useradd-g [group name or GID]-G [additional group or GID] [user name]
(2) Use the Usermod command to specify the group

# usermod-g [group name or GID]-G [additional group or GID] [user name]
(3) The Usermod command uses the-AG option to specify the added group

# Usermod-ag [group name] [user name]
(4) GPASSWD command to add the specified user to the specified group

# gpasswd-a [user name] [group name]
Note When using the Usermod command

When you use the Usermod command to specify a group with the-G option only, note that the user will exit from all of the original groups and only those specified with the-G option.

  code is as follows copy code

# Mans Usermod
-A,--append
Add the user to the supplementary group (s). Use only with THE-G option.

-G,--groups group1[,group2,... [, GROUPN]]]
A list of supplementary groups which the user is also a. Each group are separated from the next by a comma with no intervening whitespace. The groups are subject to the same restrictions as the group given with THE-G option.

If the user is currently a member of a group which isn't listed, the user would be removed from the group. This behaviour can is changed via the-a option, which appends the user to the current supplementary group list.

Actual operation

The following is an example of a Zabbix user who executes the results of gpasswd-a, usermod-g, and Usermod-ag commands.

  code is as follows copy code
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.