Linux commonly used commands-permission management

Permission management commands are mainly divided into: chmod, chown and chgrp, umask

       Remarks: It should be noted that changing file permissions requires root (super administrator) account permissions


1.chmod change the access permissions of a file or directory

Function description: modify file or directory permissions

chmod English original meaning: change the permissions mode of a file

The path where the instruction is located: /bin/chmod

grammar:

         chmod [{ugoa}{+-=}{rwx}][file or directory], such as chmod u+x file

        chmod [mode={[0-7][0-7][0-7]}] [file or directory]   such as chmod 700 file

         -R recursive modification such as chmod -R u+x directory

 

Notes:

        u=>user in ugoa refers to the user

        g=>group belongs to the user group

        o=>other other users

        a=>all all users

        +: add meaning

        -: Remove

        =: Give

        r (read): read = 4

        w(write): write=2

        x(eXecute): execute =1

 

In-depth understanding of rwx permissions

file

      r:cat/more/head/tail/less

      w: vi / vim

       x: The script has execution permission, sh script or binary executable file

 

directory:

        r:ls/ll

        w:touch/mkdir/rmdir/rm

        x: cd


2.chown changes the owner of a file or directory (user)

Example: chown new user name file/directory

 

3. chgrp changes the group of a file or directory (group)

Example: chgrp new group name file/directory

Remarks: Prerequisites for users and groups to update files or directories

            1. Have super administrator privileges (root)

            2. All users and groups have been created

=============================================

4. Default permissions of umask file

Summarize, as shown

Detailed explanation:

What is umask? What is the role of umask? , How to use umask?

umask definition

Set the "complement code" of the default permissions; when we are using the Linux system, we often need to create files and directories and other operations, then the system will default its permissions during the touch or mkdir process.

Umask is the role: control the default permissions

The default umask value is 022 (you can use the umask command to view). At this time, the default permissions of the files we create are 644 (6-0, 6-2, 6-2), and the default permissions of the created directories are 755 (7 -0,7-2,7-2)

Verify as follows

In the above figure, we know: myfile (newly created file) permissions rw- r-- r-- that is: 644 (6-0, 6-2, 6-2)

                    The permissions of mydir (newly created directory) rwx rx rx are: 755(7-0,7-2,7-2)

 Basic permissions explained

 

 

umask calculation permissions

The maximum permission of the default directory is 777, and the default maximum permission of the file is 666 (the default is no execution permission)

For the root user's umask=022

  • All permissions binary 1: represents this permission

  • umask binary 1: It means to remove this permission, no matter whether you have permission or not, you will definitely not have this permission in the end.

  • umask binary 0: means I don’t care about the permissions of the corresponding bit

The maximum permission of files and directories and the umask value are combined to obtain the default permission value; refer to umask for its function: introduction to control default permissions;

 

Modification of umask

The umask value can be divided into temporary value and permanent value;

The following picture is a temporary modification:

Permanent modification:

You can edit the following file to add umask=022.

Global configuration file: find the umask value in vim /etc/profile;

User configuration file: find the umask value in vim ~/.bashrc or add umask =022 at the end of the file; note: restart the configuration file after modification; source command;

In order to avoid unnecessary troubles, if umask needs to be modified, do not use the global configuration file, just use the configuration file that the current user belongs to;

Commonly used umask

umask  0022 

umask  0002

As shown in the figure, the system default value (/etc/profile)

Thanks: https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_001.html

Learn more and follow WeChat public account: IT Rapeseed U

Guess you like

Origin blog.csdn.net/xiaoshunzi111/article/details/114023708