Linux系统基本权限ACL及特殊权限

用户的权限

基本权限ACL

1.区别

  • ACL文件权限管理: 设置不同用户,不同的基本权限(r、w、x)。对象数量不同。
  • UGO设置基本权限: 只能一个用户,一个组和其他人
    2.语法
  • 设置用户ACL
    命令 设置 用户或组:用户名:权限 文件对象
setfacl -m u:user1:rw /home/test.txt
  • 设置组ACL
setfacl -m g:jishuzu:r /home/test.txt
  • 查看ACL权限
    命令 文件名称路径
getfacl  /home/test.txt
  • 删除部分组/用户的ACL权限
    命令 设置 用户或组:用户名:权限 文件对象
setfacl -x g:jishuzu /home/test.txt   删除组的ACL权限
setfacl -x u:user1  /hmoe/test.txt   删除用户的ACL权限
  • 删除全部
setfacl -b /home/test.txt

3.示例

  • 准备文件,查看文件权限
    在这里插入图片描述

  • 查看文件ACL权限

在这里插入图片描述

  • 设置用户user1,user2权限
[root@localhost tmp]# 
[root@localhost tmp]# setfacl  -m u:user1:rw  /home/test.txt
[root@localhost tmp]# setfacl  -m u:user2:-  /home/test.txt
[root@localhost tmp]# getfacl  /home/test.txt
getfacl: Removing leading '/' from absolute path names
# file: home/test.txt          文件名
# owner: root                 属主:root
# group: root                 属组:root
user::rw-                     用户:属主:rwx
user:user1:rw-                用户:user1:rw-
user:user2:---                用户:user2:---
group::r--                    组:属组:r--
group:jishuzu:r--             组:jishuzu:r--
mask::rw-                     掩码::rw-
other::r--                    other:其他人:r--

  • 删除全部ACL权限
[root@localhost tmp]# 
[root@localhost tmp]# setfacl -b  /home/test.txt
[root@localhost tmp]# getfacl  /home/test.txt
getfacl: Removing leading '/' from absolute path names
# file: home/test.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

特殊权限

  • 权限特殊位
4  suid    特殊用户位   (谁用谁能得到属主的权限)
2  sgid    特殊属组位   (组,目录的属组权限自动继承)
1  stick   属主删除位   (防止误删除  属主、超管能删除)

在这里插入图片描述
示例1:为cat程序加上suid权限
在这里插入图片描述
在这里插入图片描述

文件属性chattr:常用于锁定某个文件,拒绝修改
在这里插入图片描述
示例2:
1 先创建新文件进行对比。查看默认权限。

[root@localhost ~]# touch file100
[root@localhost ~]# lsattr file100
-------------- file100

2 加上不能删除的属性。

[root@localhost~]# chattr +i file100 //不能更改,重命名,删除

3 查看不同属性

[root@localhost ~]# lsattr file100
----i--------- file100

4 尝试删除

[root@localhost ~]# rm -rf file100 
rm: cannot remove `file100': Operation not permitted

5 将属性还原。

[root@localhost ~]# chattr -i file100
[root@localhost ~]# lsattr file100
-------------- file100

进程掩码 umask:新建文件、目录的默认权限会受到umask的影响,umask表示要减掉的权限
示例3:

观察系统默认掩码

[root@localhost ~]# umask
0022
[root@localhost ~]# touch  file800
[root@localhost ~]# mkdir  dir800
[root@localhost ~]# ll -d dir800 file800
drwxr-xr-x. 2 root root 6 Jul 28 08:36 dir800
-rw-r--r--. 1 root root 0 Jul 28 08:36 file800

修改shell umask值(临时)

[root@localhost ~]# umask 000
[root@localhost ~]# touch file900
[root@localhost ~]# mkdir dir900
[root@localhost ~]# ll -d dir900 file900
drwxrwxrwx. 2 root root 6 Jul 28 08:39 dir900
-rw-rw-rw-. 1 root root 0 Jul 28 08:39 file900

猜你喜欢

转载自blog.csdn.net/m0_48654420/article/details/107642790