一、基本权限UGO
1、权限对象:属主=u 属组=g 其他=o 所有人=a
ls -l 可以查看文件权限。
[root@localhost jiaofan]# ls -l file2.txt
-rw-r--r--. 1 root root 100 3月 17 21:09 file2.txt
2、权限类型:读:r=4;写:w=2:;执行:x=1;
3、使用符号:u用户 g组 o其他 r读 w写 x执行
语法: chmod 对象(u/g/o/a)赋值符(+/-/=)权限类型(r/w/x) 文件/目录
4、修改权限 chmod u+x file1
[root@localhost jiaofan]# ll
总用量 4
-rw-r--r--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]# chmod u+x file1
[root@localhost jiaofan]# ll
总用量 4
-rwxr--r--. 1 root root 106 3月 18 10:09 file1
5、执行bash file1 = ./file1
[root@localhost jiaofan]# bash file1
hello 2020
请输入您的姓名:jiaofna
哈哈 jiaofna 是大笨
[root@localhost jiaofan]#
6、用数字改变权限。4读 2写 1执行 chmod 664 file1
[root@localhost jiaofan]# ll
总用量 4
-rwxr--r--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]# chmod 664 file1
[root@localhost jiaofan]# ll
总用量 4
-rw-rw-r--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]#
7、修改文件归属权和组归属权:chown jiao1.zu1 file1
[root@localhost jiaofan]# ll
总用量 4
drwxrwxrwx. 2 root root 45 3月 18 11:29 dir1
-rwxrwxr--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]# chown jiaofan.jiaofan dir1
[root@localhost jiaofan]# ll
总用量 4
drwxrwxrwx. 2 jiaofan jiaofan 45 3月 18 11:29 dir1
-rwxrwxr--. 1 root root 106 3月 18 10:09 file1
8、修改文件归属权:chown jiao1 file1
[root@localhost jiaofan]# chown root dir1
[root@localhost jiaofan]# ll
总用量 4
drwxrwxrwx. 2 root root 45 3月 18 11:29 dir1
-rwxrwxr--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]#
9、修改文件组归属权:chown .zu1 file1
[root@localhost jiaofan]# chown .root dir1
[root@localhost jiaofan]# ll
总用量 4
drwxrwxrwx. 2 root root 45 3月 18 11:29 dir1
-rwxrwxr--. 1 root root 106 3月 18 10:09 file1
[root@localhost jiaofan]#
10、查看目录权限:ll -d dir1
[root@localhost jiaofan]# ll -d dir1
drwxrwxrwx. 2 root root 45 3月 18 11:29 dir1
11、把目录下面的权限一起改:chmod -R dir1
[root@localhost dir1]# ll
总用量 0
-rw-r--r--. 1 root root 0 3月 18 11:27 1.txt
-rw-r--r--. 1 root root 0 3月 18 11:27 2.txt
-rw-r--r--. 1 root root 0 3月 18 11:27 3.txt
[root@localhost dir1]# cd ..
[root@localhost jiaofan]# chmod -R 777 dir1
[root@localhost jiaofan]# ll dir1
总用量 0
-rwxrwxrwx. 1 root root 0 3月 18 11:27 1.txt
-rwxrwxrwx. 1 root root 0 3月 18 11:27 2.txt
-rwxrwxrwx. 1 root root 0 3月 18 11:27 3.txt
二、基本权限ACL(黑白名单):access control list
1、用户jiao2加入名单并给与读写执行的权限:setfacl -m u:jiao2:rwx file10.text
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
[root@localhost jiaofan]# setfacl -m u:jiao2:rwx file10.txt
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
user:jiao2:rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
[root@localhost jiaofan]#
2、查看文件权限:getfacl file.txt
[root@localhost jiaofan]# getfacl file10.txt
**# file: file10.txt
**# owner: user100
**# group: jishuzu******
user::rwx
user:jiao2:rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
3、删除部分:setfacl -x g:jiao2 file10.txt
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
user:jiao2:rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
[root@localhost jiaofan]# setfacl -x u:jiao2 file10.txt
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
4、删除所有:setfacl -b file10.txt
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
group::r--
group:zu1:rwx
mask::rwx
other::---
[root@localhost jiaofan]# setfacl -b file10.txt
[root@localhost jiaofan]# getfacl file10.txt
# file: file10.txt
# owner: user100
# group: jishuzu
user::rwx
group::r--
other::---