Wednesday 24 April 2013

Sticky bit

  1. What is the "sticky bit"? (t and T)

    • The sticky bit is primarily used on shared directories.  It is useful for shared directories such as /var/tmp and /tmp/ because users CAN CREATE files, READ and EXECUTE files owned by other users, but ARE NOT ALLOWED to REMOVE files owned by other users.  Of course, users CAN REMOVE their own files.

    • The sticky bit (file mode bit 01000) is used to indicate special  treatment of certain files and directories.  A directory for which the sticky bit is set restricts deletion of files it contains.  A file in a sticky directory may only be removed or renamed by a user who has write permission on the directory, and either owns the file, owns the directory, or is the super-user.   This  is  useful for directories such as /tmp, which must be publicly writable, but should deny users permission to arbitrarily delete or rename the files of others.
  2. Identifying sticky permissions.

    # ls -ld /var/tmp

    drwxrwxrwt  2   sys   sys   512   Jun 20 11:02  /var/tmp
    See the "t"?  That tells us that the sticky bit is set.
    A "T" refers to when the execute permissions are OFF.
    A "t" refers to when the execute permissions are ON.
  3. Setting sticky bit permissions.

    The leading "1" in the "chmod" command sets the sticky bit.

    # chmod 1771 <path_to_directory> (permissions for "other" have execute bit ON)

    drwxrwx--t  

    # chmod 1770 <path_to_directory> (permissions for "other" have execute bit OFF)

    drwxrwx--T

0 blogger-disqus:

Post a Comment