Linux Getting Started user and group management class commands

Source: Internet
Author: User

Before learning the user and group management commands, we first need to understand the ID of this basic command, it is to display the current user's identity information, the user will inevitably involve the concept of the group, then let us look at the relevant user and group commands.

1. Id

ID Current user's own information

Grammar

ID option parameter (user name)

Options and Parameters

ID User name Displays information for the specified user

  [[email protected] ~]#  uid=0 (root) gid=0 (root) groups=0 (root) Context=unconfined_u: Unconfined_r:unco   nfined_t:s0-s0:c0. c1023

Id–u User name Displays the UID of the specified user

id–g user name displays the primary group GID for the specified user

[[email protected] ~]#   id-g Alice

Id–un User Name displays the name of the specified user

  [[Email protected] ~] # Id-un Alice      Alice

ID–GN User name displays the primary group GID for the specified user

[[Email protected] ~] # id-gn Alice    G2

2. Users

    • Useradd for creating users

Syntax:
Useradd option parameter (user name)
Options and Parameters:
             Useradd-u specifying UID
-O with-u, does not check UID uniqueness
-G Gid/Group name specifies the user's primary group
-G Gid/Group name specifies the user's additional group
- C "comment" User name
-d Specifies the user's default shell
-N Use the Users group as the primary group
- R Create system user
-M is used with-R to create a home directory while creating a system user
-M does not create a home directory when creating a non-system user
-D sets default values that affect the following files
Example 1          

[[Email protected] ~] # useradd-u 521 ABC [[Email protected] ~] # id-u ABC  521

This command creates an ABC user with a UID number of 521.

Example 2

[[Email protected] ~] # useradd-u 521-o BC [[Email protected] ~] # ID BC uid=521 (ABC) gid=522 (BC) groups=521 (ABC)

When this command is used with-u and-O, the UID is not checked for repetition, even if the UID number exists and can still be created.

Example 3

[[Email protected] ~] # useradd-g G2 D [[Email protected] ~] # ID D uid=523 (d) gid=523 (d) groups=523 (d), 510 (G2)

This command creates a user of D, whose subordinate group is G2.

    • Userdel Delete a user that is no longer in use

Grammar:
Userdel option parameter (user name)
Options and Parameters:

-R with the user's home directory deleted together

-F Force Delete user

The common option of the Delete command is-R, so that it can be deleted thoroughly, home directories and mailboxes are not present.

[[Email protected] ~] # Userdel-r D

    • Modify User Permissions

Usermod
-u UID user name modifies UID of specified user
- G Gid/Group name Modify the user's primary group (the group must first exist)
-G Gid/Group name [gid2/group name 2 ...] Set up additional groups for users
-A and-g configuration increases the user's additional group
-S Shell modifies the user's default shell
-C ' comment content ' Modify user's comments
-D new Address user name only modifies the information in the home directory in/etc/passwd and does not migrate the directory
-M with the-D with modify home directory, the directory is migrated together
Note:-D must be connected with the address
-L new name old name Modify user's login name
-L User name lock user's password
-u user name unlocks user's password

Example 4

[[Email protected] ~] # usermod-g G1 Alice [[Email protected] ~] # ID Alice uid=502 (Alice) gid=509 (G1) groups=509 (G1)

Modify the user's primary group and change the primary group to G1.

Example 5    

[[Email protected] ~] # usermod-g G2 Alice [[Email protected] ~] # ID Aliceuid=502 (Alice) gid=509 (G1) groups=509 (G1), 510 (G2)

Sets G2 to set the additional group for user Alice.

Example 6

~]#  usermod-s sbin/nologin Alice 

3. Group-related

    • Groupadd

Options and Parameters
-G Group ID Group name
-R automatic Partitioning group ID CENTOS6 < CENTOS7 <1000

Example 7

      [[Email protected] ~] # Groupadd group1

Add New group Group1

Example 8        

  [[Email protected] ~] # groupadd-g 101 Group

Add the new group group2, and set the group identification number to 101.

    • Groupmod
      -N New group name current group name
      -G new ID Current group name

Example 9

    [[Email protected] ~] #

Change the group identification number to 102.

    • Groupdel
      Groupdel Group name Delete Group
    • gpasswd
             gpasswd    -a     username  groupname       Adds the specified user to the specified group as an additional group
            gpasswd    -d      Username groupname       removes the specified user from the specified group
            gpasswd    -A admin1[,admin2 ...] groupname     set up the group administrator, the administrator can
      Modify the group password, and modify group members

Gpasswd-m user1,user2 GroupName set Group membership list (root only)
Gpasswd-m ' groupname delete all members composed of
Gpasswd-r G Roupname Clears the group password for the specified group

Attention:
Each user has and only one primary group, but the user can have 0 to multiple additional groups

Each file can have only one owner, and one owning group
When a user accesses a file, it first determines whether the current user is the owner of the file,
If it is owner, the permission to apply the owner bit, if not owner, determines whether a group of that user belongs to the same group as the file, and if so, applies the group bit permissions, if not, the other bit.




Linux Getting Started user and group management class commands

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.