linux粘滞位

权限粘滞位
通常情况下⽤用户只要对某个⽬目录具备w写⼊入权限,便可以删除该⽬目录中的任何⽂文件,⽽而不论这个⽂文件的权限是什么。

看现象,我们在超级用户下,创建一个目录,在该目录下创建一个文件test.c,默认文件权限是644

[root@bogon 3_29]# mkdir temp
[root@bogon 3_29]# ll
total 4
drwxr-xr-x. 2 root root 4096 Mar 28 10:44 temp
[root@bogon 3_29]# 
[root@bogon 3_29]# touch temp/test.c
[root@bogon 3_29]# ls
temp
[root@bogon 3_29]# cd temp
[root@bogon temp]# ll
total 0
-rw-r--r--. 1 root root 0 Mar 28 10:46 test.c

退出成为普通用户,

[root@bogon 3_29]# touch temp/file1
[root@bogon 3_29]# ll temp/file1
-rw-r--r--. 1 root root 0 Mar 28 11:05 temp/file1
[root@bogon 3_29]# exit  //退出超级用户
[admin@bogon 3_29]$ rm temp/file1
rm: remove write-protected regular empty file `temp/file1'? y  //成功删除
[admin@bogon 3_29]$ ls
temp
[admin@bogon 3_29]$ ll temp/file1    //文件已经被删除
ls: cannot access temp/file1: No such file or directory
[admin@bogon 3_29]$ 

通过上面的操作可以发现,虽然普通用户对文件temp/file1只具备r”r–”权限,但因为从temp目录获得了“rwx”权限,因而仍然可以将temp/file1删除。
粘滞位权限便是针对这种情况设置,当目录被设置了粘滞位权限以后,即后,即便用户对该目录有写入权限,也不能删除该目录中其他用户的文件数据,而只有该文件的所有者和root用户才有权将其删除。

设置了粘滞位之后,正好可以保持⼀一种动态的平衡:允许各⽤用户在
目录中任意写⼊入、删除数据,但是禁⽌止随意删除其他⽤用户的数据。
需要注意的是,粘滞位权限只能针对⽬目录设置,对于⽂文件⽆无效
设置了粘滞位权限的⽬目录,使⽤用ls命令查看其属性时,其他⽤用户权
限处的“x”将变为“t”。

粘滞位权限都是针对其他⽤用户(other)设置,使⽤用chmod命令设置
⽬目录权限时,“o+t”、“o-t”权限模式可分别⽤用于添加、移除粘滞位权
限。

[root@bogon 3_29]# chmod o+t temp
[root@bogon 3_29]# ls -ll
total 4
drwxrwxrwt. 2 root root 4096 Mar 28 11:06 temp

其他用户的权限改为了t

[root@bogon 3_29]# touch temp/file1
[root@bogon 3_29]# exit
[admin@bogon 3_29]$ rm temp/file1
rm: remove write-protected regular empty file `temp/file1'? y
rm: cannot remove `temp/file1': Operation not permitted  //权限不够,无法完成删除
[admin@bogon 3_29]$ 

当需要为⽤用户提供⼀一个开
放⽬目录⽽而又不希望造成管理混乱时,通过为⽬目录设置粘滞位权限便
可以解决问题。

chmod o+t temp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值