【LINUX】Linux下的粘滞位

     In computing, thesticky bit is a user ownership  access right flag that can be assigned to files and directories on Unix-like systems.

    When a directory's sticky bit is set, the filesystem treats the files in such directories in a special way so only the file's owner, the directory's owner, or root user can rename or delete the file. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of the file's owner. Typically this is set on the/tmp directory to prevent ordinary users from deleting or moving other users' files.

     Remark:the Linux kernel ignores the sticky bit on files. When the sticky bit is set on a directory, files in that directory may only be unlinked or renamed by root or the directory owner or the file owner.                                                                        

                                                                                                                                                                                       -Wikipsdia 
   

      在计算中,粘滞位是可以分配给类Unix系统上的文件和目录的用户所有权的访问权限标志。
      当目录的粘滞被设置时,文件系统以特殊的方式处理这些目录中的文件,因此只有文件的所有者,目录的所有者或root用户可以重命名或删除该文件 。没有设置粘滞位,任何具有该目录的写入和执行权限的用户都可以重命名或删除目录所包含的文件,无论谁是文件的拥有者。 通常会在/ tmp目录中设置粘滞位,以防止普通用户删除或移动其他用户的文件。
     备注:Linux内核忽略文件上的粘滞位。 当目录上设置粘滞位时,该目录中的文件只能由root或目录所有者或文件所有者取消链接或重命名。


 接下来看一个例子:在root用户下建立一个tmp目录,并将其的权限设置为777.


 在tmp目录下建立test.c文件,退回到当前目录,我们对tmp文件进行删除操作。


由于tmp对其他用户的权限没有限制,因此可以删除成功。

接下来设置粘滞位。粘滞位权限都是针对其他用户(other)设置,使用chmod命令设置目录权限时,“o+t”

“o-t”权限模式可分别用于添加、移除粘滞位权限。


可以看到tmp的权限已经由x变为t,再次在当前用户下对text.c进行删除操作。


我们发现已经不能对text.c进行删除操作,说明设置成功,也完成了对粘滞位的简单验证。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值