Centos7--10. Group management and rights management (rights management)

Introduction 1. Basic rights (file / directory)

ls -l content displayed as follows:
-rwxrw-r-- 1 root root 1213 Feb 2 09:39 abc
1) Bit 0 determining the file type (D, -, L, C, B)
2) bits 1-3 determine the owner (owner change the file) have access to the file . The User ---
3) 4-6 to determine the position belongs to the group (the same group of users) have access to the file. Group ---
4) 7-9 to determine the position of the file to other users. --- Other

figure 1

2. rwx permissions Detailed

2.1 rwx role to file

1) [r] Representative read (read): read, view
2) [w] Representative writable (write): can be modified, but does not mean change can delete a file, delete a file on the premise that the document is located the directory has write permissions to delete the file.
3) [x] Representative executable (execute): may be performed

2.2 rwx role to directory

1) [r] Representative read (read): read, LS view contents of
2) [w] Representative writable (write): can be modified to create the directory rename directory Remove + +
3) [x] Representative perform (execute): you can enter the directory

3. actual case file and directory permissions

ls -l display contents are as follows :( remember)
-rwxrw-r-- 1 root root 1213 Feb 2 09:39 abc

Explained as follows:

10个字符确定不同用户能对文件干什么
第一个字符代表文件类型:文件(-),目录(d),链接(l)
其余字符每 3 个一组(rwx)读(r)写(w)执行(x)
第一组rwx:文件拥有者的权限是读、写和执行
第二组rw-:与文件拥有者同一组的用户的权限是读、写但不能执行
第三组r--: 不与文件拥有者同组的其他用户的权限是读不能写和执行

可用数字表示为:r = 4,w = 2,x = 1 因此 rwx = 4 + 2 + 1 = 7

1           文件:硬链接数或 目录:子目录数
root        用户
root        组
1213        文件大小(字节),如果是文件夹,显示 4096 字节
Feb 2 09:39 最后修改日期
abc         文件名

4. Modify permission -chmod

4.1 Basic instructions

通过 chmod 指令,可以修改文件或目录的权限

4.2 The first way: +, -, = change permissions

u: 所有者 g:所有组 o:其他人 a:所有人 (u、g、o 的总和)
1)chmod u=rwx,g=rx,o=x 文件目录名
2)chmod o+w 文件目录名
3)chmod a-x 文件目录名
  • Case presentation

    1) to read and write permission to the owner of the file abc executed, to read where the group permission to execute, execute permission to other groups to read
    2

    2) to the owner of the file to remove the permission to perform abc, increasing the group write permissions
    3

    3) to all users abc files to add permissions to read
    4

4.3 The second way: by changing the digital rights

规则:r=4 w=2 x=1 ,rwx=4+2+1=7
chmod u=rwx,g=rx,o=x 文件目录名
相当于 chmod 751 文件目录名
  • Case presentation
    requirements: the file to modify the permissions /home/abc.txt rwxr-xr-x, used to digitally implemented
    rwx. 4 = + 2 + =. 1. 7
    RX + =. 4. 5. 1 =
    RX = +. 1. 4 = 5
    command: chmod 755 /home/abc.txt

5. Modify the file owner -chown

5.1 Basic Introduction

owner chown newowner file change file
chown newowner: the owner's group newgroup file and change the user
-R if it is a directory then all child files or directories recursively into force

5.2 Case presentation

Owner 1) Please /home/abc.txt files modified to tom
5

Under 2) set the / home / kkk directory owners of files and directories are modified to tom
preferred to use root operation
6

6. Modify the file's group -chgrp

6.1 Basic Introduction

All group chgrp newgroup file change file

6.2 Case presentation

1) where the group set /home/abc.txt files modified to bandit (bandit)
chgrp Bandit /home/abc.txt

Group where all of the files and directories under 2) Set / home / kkk directory is modified to Bandit (bandit)
chgrp -R & lt Bandit / home / kkk
7

7. 最佳实践-警察和土匪游戏

police, banlit
jack,jerry:警察
xh,xq:土匪

(1)创建组
bash>groupadd police
bash>groupadd bandit

(2)创建用户
图8

(3)jack 创建一个文件,自己可以读写,本组人可以读,其他组没有任何权限
图9

(4)jack 修改该文件,让其他组可以读,本组可以读写
图10

(5)xh 投靠警察,看看是否可以读写
先用 root 修改 xh 的组:
图11

使用 jack 给他的家目录 /home/jack 的所在组一个 rx 的权限
图12

xh 需要重新注销 再到 jack 目录就可以操作 jack 的文件
图13

Guess you like

Origin www.cnblogs.com/zwxo1/p/11390349.html
Recommended