Skip to content

[Linux] Explanation Of Sticky Bit (chmod 1777)

Introduction

The sticky bit is an interesting application in Unix and Unix-like systems. It represents a special permission setting that offers more nuanced operations for files and directories. Most are familiar with file permissions, categorized into three distinct types: rwx (read, write, execute). The sticky bit goes a step further by regulating the rights to “delete” and “rename” files.

In system like Linux, we’re accustomed to using the chmod command to change access permissions for files and directories. To set the sticky bit, one needs to use the numbers 1777 or 3777 to enable this special permission setup.

  1. chmod 1777
    This setting is used for directories. The 1777 setting, known as the Sticky Bit, implies that only the file owners or root can delete or move files within the directory. However, the regular read, write, and execute permissions (rwx) are granted to all users (owner, group, others).

    To remove the sticky bit, one can use chmod 0777 or chmod -t.

    A classic use case is public spaces like /tmp. Anyone can create and write files, but only the file owners and superuser can delete or rename them.
  2. chmod 3777
    This is a variant of 1777 but adds the “Set User ID bit” (SUID). Set User ID bit (SUID): When set on an executable file, no matter who executes the file, it will run with the file owner’s permissions. On directories, SUID usually has no special effect, so in practice, 3777 and 1777 often serve similar purposes.

I’m documenting this article purely because a colleague recently discussed this peculiar setting. Upon researching, I discovered its existence. It serves as a reminder that while I rely on Linux for development, my capabilities as an administrator still have much room for growth.


References


Read More

Tags:

Leave a Reply