【Linux】Linux permissions

  5a2585dded9b416fb4ea58637b42ed39.png

  Yan-yingjie's homepage

Awareness of the past, not remonstrance, knowing the future, can be pursued  

C++ programmer, 2024 electronic information graduate student


Table of contents

Linux permission concept

        1. Classification of users under Linux

             The difference between root and ordinary users?

             switch between users

        2. What is authority

                1. Authority authentication is identity (authority is related to "person")

                2. Permissions are also related to the attributes of things

       3. How to treat the suffix problem?

        4. Addition and deletion of permissions


Linux permission concept

        1. Classification of users under Linux

               root: super user

                Ordinary user: our new user, adduer yqy--new user

             The difference between root and ordinary users?

               Root is basically not restricted by permissions, and ordinary users are restricted by permissions

                Note:

                Both root and ordinary users must set passwords 

             switch between users

                

//普通用户切换到root用户
su
//不过身份完成转换后,但是仍旧处于普通用户目录下,但是权限提高了
//password:直接输入密码即可

su -
//切换到root用户下

//直接切换到yqy用户
su yqy

//指令提权
sudo whoami
//我们用adduser新创建的用户,没有颁发执行sudo,系统不信任,我们手动将其添加到系统白名单中

//编译文件
nano test.cc

        2. What is authority

                Is a thing allowed to be done

                1. Authority authentication is identity (authority is related to "person")

                2. Permissions are also related to the attributes of things

                     File type: The file name suffix in the Linux system has no direct meaning

         First column: file type

                       -: Ordinary files: text, executable programs, and libraries are basically ordinary files

                      d: directory file: directory

                      b: block device file: block device file

                      c: character device files: keyboard, display files

                      p: pipeline file: used for communication

       The second column: the permission attribute of the file

                      r: readable (read permission)

                      w: writable (write permission)

                      x: Executable (executable permission)

                     Three and three are a group, the first three characters represent the owner's authority, and the middle three characters represent the group's authority.

The last three are other permissions

        Third column: file owner

        The fourth column: the group to which the file belongs

        Fifth column: file size

        The sixth column: the last operation time of the file

        

       3. How to treat the suffix problem?

                        ①, gcc is a compiler, but it does not mean that running software under Linux does not require other suffixes

                        ②, depending on user needs

        4. Addition and deletion of permissions

//删除指定用户和文件的权限
chmod u-r test.cc

//增加指定用户和文件的权限
chmod u+r test.cc

//增加所属组的权限
chmod g+rw test.cc

//增加其他人的权限
chmod o+r test.cc

//采用八进制方式增加权限
chmod 000 test.txt

        Note: $ is the command line prompt of ordinary users, # is the command line prompt of super users

        Permissions for directory types

        r: Whether to allow to view the contents of the specified directory

        w: Whether to allow creation and changes in the current directory

        x: Whether to allow users to enter the corresponding directory

        ①. Any files created by the user in their own home directory cannot be accessed by other users

        ② Whether a file can be deleted is not determined by the file itself, but by the directory where the file is stored

        ③. If we remove the w permission of the shared directory, we cannot create files at the same time

        ④, sticky bit: set for the directory, generally a shared directory, everyone can add, delete, and check their own files in the directory

Change, after setting the sticky bit, except for root and the current user, other users I send to delete it, which is a special permission

Guess you like

Origin blog.csdn.net/m0_73367097/article/details/130884608