Centos user and group management

Source: Internet
Author: User

I. Group Management

1.Add User Group

Groupadd

 

2.Delete User Group

Groupdel

 

3.Modify user group

Groupmod

 

4.Switch User Group

Newgrp <groupname>

If a user belongs to multiple user groups at the same time, you can use Newgrp Command to switch to the target group, so that you can have the permissions of this group.

 

5.View All groups

All groups are actually /Etc/group Filter the file content.

CAT/etc/group | awk-F: '{print $1 }'

 

6.View User Groups

Groups <username>

 

Ii. User Management

1.Add User

Useradd <username>-D <path>-m-g-P

The common parameters are as follows:

-D : Specifies the user's main directory. If this directory does not exist, use -M This directory is created.

-M : Create a user's home directory

-G : User Group ID

-G : User Group Name

-P : Logon password. Note that the logon password is not in plain text and is the encrypted password.

 

E.g.

Useradd testuser-m-g mygroup

A Testuser And automatically create /Home/testuser And add the user Mygroup Group.

 

2.Delete a user

Userdel-F-r <username>

-R : Delete the user's home directory and emails in the mailbox

-F : Forcibly delete files, even if the owner is not the user

 

3.Modify user

Usermod <username>-D <path>-m-g-P

Parameter meaning and Useradd Roughly the same

 

4.User Password

Passwd <username>: Change Password

Passwd-D <username>: Command to delete the user's password, that is, the next login without a password.

Passwd-L <username>  : Lock the user so that it cannot log on

 

 

Iii. File owner Management

1.Change owner

Chown-r <username>. <groupname> File

-R : Indicates recursive changes.

 

E.g.

Chown-r testuser. newgroup testpath

The above command will Testpath Change the owner of all files under the path Testuser , Change all owning groups Newgroup .

 

2.Set file mask

Umask [a1 A2 A3]

Users can use Umask Command to set the default file generation mask. The default generated mask tells the system which permissions should not be granted to create a file or directory. If you set Umask Place commands in Environment files . Bash_profile To control the access permissions of all newly created files and directories.

A1Indicates that the permission of the owner is not allowed, A2Indicates that permissions of the same group are not allowed, A3This means that the permissions of others are not allowed.

Umask 022: Indicates that the setting does not allow users in the same group and other users to have write permissions.

umask : displays the current default generated mask.

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.