Linux基本操作(4)-用户权限的管理

一、基本权限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::---
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值