Confusion with the sticky bits (sticky bit) of Linux files and directories (RPM)

Source: Internet
Author: User


Today's maintenance of the system found a very strange problem: AAA users and BBB users belong to the same AAA group, but with AAA user-created files, permissions set to 777, or can not be deleted with BBB users. Weird!

After several turnover, found that AAA user to create the file location of the upper directory permissions is DRWXRWXRWT, do development for so many years, have not seen the so-called "T" permission, so found a company's Linux master Help, master crackling did a bunch of tests, and then Google on the search "RWT Linux ", finally found the problem, found that the use of the name is" file sticky bit (sticky) bit. " Its function is: the ordinary file sticky bit will be ignored by the Linux kernel, but the sticky bit of the directory indicates that the files in this directory can only be deleted by owner and Root, yes this is the nature of the problem, it is also consistent with my phenomenon. So with the root user, after this folder Chmod-t, with the BBB user can delete just AAA user created files. Everything's fine. Wow.... The world is peaceful! It's been a long time. So this knowledge point is organized as follows:

  
 
  1. 文件的粘滞位(sticky)位是作什么用的?
  2. 普通文件的sticky位会被linux内核忽略,of the Catalog Sticky indicates that files in this directory can only be owner and the Root Delete
  3. 粘着位(Sticky bit)
  4. 如果用户对目录有写权限,则可以删除其中的文件和子目录,即使该用户不是这些文件的所有者,而且也没有读或写许可。粘着位出现执行许可的位置上,用t表示,设置了该位后,其它用户就不可以删除不属于他的文件和目录。但是该目录下的目录不继承该权限,要再设置才可使用。
  5. # chmod 1770 xxx
  6. 举一个linux下的常见目录来做例子,也就是 /tmp 目录来说一下粘连位的作用。
  7. #ls -dl /tmp
  8. drwxrwxrwt 4 root root .........
  9. 注意other位置的t,这便是粘连位。
  10. 我们都知道,/tmp常被我们用来存放临时文件,是所有用户。但是我们不希望别的用户随随便便的就删除了自己的文件,于是便有了粘连位,它的作用便是让用户只能删除属于自己的文件。
  11. so the original execution flagxwhere did it go? This is how the system is set up, if there had been in that positionx, then these special signs (suid,Sgid,Sticky) Display as lowercase letters (s,s,T). otherwise, Display as uppercase letters (S,S,T) .
  12. 3)粘着位(sticky)
  13. eg:
  14. chmod 777 abc
  15. chmod +t abc
  16. 等价于
  17. chmod 1777 abc
  18. 在以前旧的系统当中,如果一个程序文件一旦设置了粘着位,
  19. 那么当该程序中止的时候他的所有指令段将被保存到系统的交换分区当中,
  20. 再次运行时可以更快的调入系统.
  21. 不过现在的操作系统已经不再使用这种功能了.
  22. 但这并不表示这一功能已经完全被废弃.
  23. 当一个目录设置为粘着位时,它将发挥特殊的作用,
  24. 即当一个目录被设置为"粘着位"(用chmod a+t),则该目录下的文件只能由
  25. 一、超级管理员删除
  26. 二、该目录的所有者删除
  27. 三、该文件的所有者删除
  28. 也就是说,即便该目录是任何人都可以写,但也只有文件的属主才可以删除文件。

author:http://dongwei.iteye.com/blog/921961


From for notes (Wiz)

Confusion with the sticky bits (sticky bit) of Linux files and directories (RPM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.