linux 中 类/tmp目录权限(粘滞位权限)
粘滞位权限确保文件只能被文件的所有者(或者root用户)删除而不能被其他用户删除。linux系统中根目录下/tmp/默认设置了粘滞位权限。
001、设置粘滞位权限之前
[root@pc1 /]# pwd ## 当前目录 / [root@pc1 /]# whoami ## 当前用户 root [root@pc1 /]# mkdir test_dir ## 创建测试目录 [root@pc1 /]# chmod 777 test_dir/ ## 权限开满 [root@pc1 /]# ls ## 列出所有内容 bin dev home lib64 mnt proc run srv test_dir usr boot etc lib media opt root sbin sys tmp var
002、测试
a、user01在 /test_dir 目录中创建文件
[user01@pc1 ~]$ ls [user01@pc1 ~]$ whoami user01 [user01@pc1 ~]$ cd /test_dir/ [user01@pc1 test_dir]$ ls [user01@pc1 test_dir]$ echo "hello world" > user01.txt [user01@pc1 test_dir]$ ls user01.txt
b、user02进入/test_dir并尝试删除 user01.txt文件
[user02@pc1 ~]$ ls [user02@pc1 ~]$ whoami ## 当前用户 user02 [user02@pc1 ~]$ cd /test_dir/ ## 进入指定目录 [user02@pc1 test_dir]$ ls user01.txt [user02@pc1 test_dir]$ rm user01.txt ## 删除user01创建的文件 user01.txt,可以删除,这说明用户之间可以删除文件,只要对上级目录有写的权限 rm: remove write-protected regular file ‘user01.txt’? y [user02@pc1 test_dir]$ ls
。
003、对/test_dir设置粘滞位权限
[root@pc1 /]# ls bin dev home lib64 mnt proc run srv test_dir usr boot etc lib media opt root sbin sys tmp var [root@pc1 /]# ls -ld test_dir/ ## 列出test_dir目录此时的权限 drwxrwxrwx. 2 root root 6 Dec 30 19:56 test_dir/ [root@pc1 /]# whoami ## 列出当前用户 root [root@pc1 /]# chmod -R o+t test_dir/ ## 对目录test_dir设置粘滞位权限 [root@pc1 /]# ls -ld test_dir/ ## 查看此时的test_dir目录的权限 drwxrwxrwt. 2 root root 6 Dec 30 19:56 test_dir/
004、测试效果
a、uer01在/test_dir目录中创建文件
[user01@pc1 test_dir]$ ls [user01@pc1 test_dir]$ whoami ## 当前用户 user01 [user01@pc1 test_dir]$ pwd ## 当前目录 /test_dir [user01@pc1 test_dir]$ echo "hello world" > user01.txt ## 创建文件 [user01@pc1 test_dir]$ ls user01.txt
b、user02进入/test_dir目录,尝试删除user01创建的文件 user01.txt
[user02@pc1 test_dir]$ whoami ## 当前用户 user02 [user02@pc1 test_dir]$ pwd ## 当前目录 /test_dir [user02@pc1 test_dir]$ ls user01.txt [user02@pc1 test_dir]$ rm -f user01.txt ## 删除文件,可见已经无法删除,说明粘滞位权限已经发挥作用 rm: cannot remove ‘user01.txt’: Operation not permitted
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2021-12-30 R语言中判断两个数据框是否完全相同
2021-12-30 R语言中order排序出现2大于10的情况?
2021-12-30 R语言中NA的判断
2020-12-30 centos7 中 安装gcc编译器
2020-12-30 vmware虚拟机安装mint-20全过程
2020-12-30 vmware虚拟机安装deepin20全过程
2020-12-30 vmware虚拟机安装openSUSE-Leap-15.2全过程