Fact-checked by Grok 2 weeks ago

Sticky bit

In , the sticky bit is a special permission flag in operating systems that can be set on files or directories to control access and execution behaviors. Originally introduced in early Unix systems around , it was applied to files to retain the program's text segment in swap space after execution, thereby accelerating subsequent loads of frequently used programs. This historical functionality has largely been deprecated in modern systems due to advancements in , where the bit on files typically has no effect or is ignored. Today, its primary and most notable use is on directories, where it restricts the deletion or renaming of files within a shared writable to only the file's owner, the 's owner, or privileged users such as , preventing unauthorized removal by other users with write access. This feature is commonly employed in public directories like /tmp to maintain in multi-user environments. The sticky bit is part of the extended file permission model in systems, alongside and setgid bits, and is represented in the file mode bits as a special bit (octal 1000 or 512), separate from the standard permissions, defined as S_ISVTX in . When viewed with the ls -l command, it appears as a 't' in the permissions string if execute permission is also set for others (e.g., drwxrwxrwt), or 'T' otherwise. It can be set using the chmod command with symbolic notation (chmod +t [directory](/page/Directory)) or numeric notation (e.g., chmod 1777 [directory](/page/Directory), where the leading '1' enables the sticky bit). In -compliant systems, this bit is defined under the S_ISVTX macro in header files like <sys/stat.h>, ensuring portability across Unix variants. While its file-related role has faded, the sticky bit remains a fundamental mechanism for protection, highlighting the of Unix permissions from performance optimization to .

Overview

Definition

The sticky bit is one of three special permission bits in operating systems, alongside the and setgid bits, which modify the behavior of file access beyond standard read, write, and execute permissions. It is represented in the file permission string as a modification to the execute permission for the "other" user category, typically appearing as a lowercase 't' in the tenth character position of the long listing output (e.g., rwxrwxrwt), indicating its role in the final triplet of permissions. In binary terms, the sticky bit is set by the 0x200 bit ( 512, 1000) within the file mode field, as defined in the st_mode member of the structure. Historically, when applied to executable files, the sticky bit served to retain the program's image in memory after execution to improve performance by avoiding reloading from disk on subsequent runs, a feature originating from early Unix systems. However, on modern systems, this effect on files is obsolete and has no practical impact, with the bit primarily functioning when set on directories. When the sticky bit is enabled on a , it enforces a restriction such that within that can only be unlinked (deleted) or renamed by the owner of the , the owner of the , or a privileged (such as ), regardless of whether other users possess write permissions on the itself. This mechanism provides a layer of protection in shared environments, preventing unauthorized interference with created by others.

Purpose

The sticky bit primarily enhances security in multi-user operating systems by restricting the ability to delete or rename files within a directory to only the file's owner, the directory's owner, or a privileged user, even when other users hold write permissions to the directory itself. This permission flag, often denoted by a 't' in file listings, addresses vulnerabilities inherent in shared writable spaces where unauthorized modifications could compromise system integrity or user data. A common application of this feature occurs in temporary directories like , enabling multiple users to create and access files collaboratively without the risk of one user overwriting or removing another's work, thereby fostering safe multi-user interactions in environments such as development servers or public workstations. Historically, the sticky bit served a different purpose when set on files: it directed the operating system to retain the program's text in swap after execution, facilitating quicker reloading for repeated invocations in resource-constrained systems; this mechanism has become obsolete in contemporary implementations. In broader terms, the sticky bit mitigates security risks in collaborative file systems by preventing denial-of-service attacks, where a malicious with write access to a could otherwise delete essential files to disrupt operations or services.

History

Origins in Early Unix

The sticky bit was introduced in the Fifth Edition of Unix, released in June 1974 by and at Bell Laboratories. This edition marked a significant step in Unix's development on the minicomputer, incorporating enhancements to the amid the system's evolution from its origins. Originally designed for executable files, the sticky bit served to mark programs such that their text segments—containing the read-only —remained resident in or swap space even after execution completed. Implemented as the 001000 flag in the i-node structure, it addressed performance bottlenecks on resource-constrained hardware by preventing the need to reload frequently used binaries from disk, thereby reducing I/O overhead in multi-user scenarios. This mechanism complemented Unix's core strategy, where process text segments were shared and write-protected to promote in a environment supporting up to dozens of concurrent users on limited . In the broader context of early Unix's file permission model, the sticky bit formed part of the i-node's mode bits, which already included read/write/execute permissions for owners and others, alongside the set-user-ID bit. Its inclusion reflected the system's emphasis on optimizing resource utilization for a setup, where disk access times (around 20-30 ms seek) and modest memory (typically 64-128 KB) necessitated clever techniques to minimize and paging. The feature's first documentation appeared in the UNIX Programmer's for the Fifth Edition, detailing its role in the without extensive user-facing commands at the time.

Evolution Across Systems

The sticky bit's role evolved significantly from its initial application to executable files toward a primary focus on directories for security in multi-user environments. In 4.3BSD, released in , the bit was adapted for use on directories to prevent unprivileged users from removing or renaming files owned by others within shared, world-writable directories, thereby addressing vulnerabilities in collaborative spaces like temporary file storage areas. Over time, the sticky bit's original functionality for files—intended to retain text in —was deprecated across major Unix variants due to advancements in management that rendered it obsolete. In , the bit has never been implemented on files and is ignored. BSD systems followed suit, with dropping support for files in version 2.2.1 (released in 1996) and in version 3.7 (released in 2002), limiting it thereafter to directories. In contrast, proprietary systems like and retained file support into the 2000s, with documentation describing potential effects on regular files as late as version 11i. phased out file-related behavior by 2005, coinciding with the 10 release, after which official documentation emphasized directory usage exclusively. This transition to directory-only application solidified as a core feature in POSIX-compliant systems during the , with the standard defining the sticky bit (S_ISVTX) to file removal or renaming in a to the file's owner, the 's owner, or a privileged , a mechanism widely adopted for safeguarding shared resources such as /tmp. As of 2025, the sticky bit remains implemented solely for in contemporary systems including , macOS (derived from BSD), and modern BSD variants like and , with its behavior unchanged since around 2010 and no notable deprecations or enhancements reported.

Technical Implementation

Permission Storage

The sticky bit is stored within the inode structure of Unix-like file systems, specifically in the st_mode field as bit 9 (0-based from the least significant bit, value 0x200 or 01000) of the 12-bit permission mode. This bit is part of the broader mode field that also accommodates the (octal 04000) and setgid (octal 02000) bits, allowing these special permissions to be represented compactly alongside standard read, write, and execute permissions. In notation, the sticky bit is indicated by adding 1 to the thousands place of the four-digit permission value. For instance, the mode 1777 combines full read-write-execute permissions for owner, group, and others (0777) with the sticky bit (1000), resulting in rwxrwxrwt for a . When displaying permissions via tools like the command, the sticky bit appears symbolically in the permission string: as a lowercase t appended to the others' execute position if the execute bit is set (e.g., rwxrwxrwt), or an uppercase T if the execute bit is unset (e.g., rwxrwxrwT). Implementation of the sticky bit occurs at the level across operating systems, ensuring compatibility regardless of the underlying . This includes support in Linux's , macOS's APFS (where it is defined as S_ISVTX with 0001000 in <sys/stat.h>), and BSD's UFS.

Enforcement Mechanisms

The operating system kernel enforces the sticky bit primarily during file system operations that could alter or remove entries within a directory, such as unlink() and rename(), by performing ownership checks on the calling process. Specifically, if the sticky bit is set on the parent directory, the kernel verifies whether the effective user ID of the process matches the owner of the target file, the owner of the directory, or the superuser (root); if none of these conditions are met—even if the process has write permission on the directory—the operation is denied to prevent unauthorized deletions or renames in shared environments. This enforcement aligns with standards, where the sticky bit (S_ISVTX) on directories restricts removal or renaming of files to the file owner, directory owner, or a privileged process, as defined in POSIX.1-2008; the behavior for non-directory files is unspecified and typically ignored in compliant systems. In , these checks occur at the Virtual File System (VFS) layer through inode operations, where the examines the directory's mode bits during unlink() and rename() calls; for instance, in the namei.c implementation, the VFS denies the operation with EPERM if the sticky bit is set and the process lacks the CAP_FOWNER capability or appropriate ownership. In macOS and BSD variants like and , enforcement is similarly handled via inode-based permission checks in the , restricting unlink() and rename() to the file owner, directory owner, or when the sticky bit is active on the directory. Solaris implements comparable directory enforcement, denying unlink() or rename() unless the user owns the file, owns the directory, or is , with EACCES returned on failure; In , the sticky bit on non-executable files such as swap files indicates that the file contains swap data, so that when accessed, its pages are not retained in the system's . This prevents flushing more valuable data from the and avoids conditions that could arise if the swap data were paged out. If an unlink() or rename() attempt violates the sticky bit restrictions, the kernel returns EACCES (permission denied) or EPERM (operation not permitted) to the calling process, signaling the access failure without altering the file system state. The sticky bit itself is represented in the inode's mode field, typically as the S_ISVTX flag.

Usage

On Directories

In contemporary Unix-like operating systems, the sticky bit serves a critical role on directories by restricting the deletion or renaming of files within them to only the file's owner, the directory's owner, or a privileged user such as root, even when the directory permissions allow writing by other users. This functionality is particularly valuable in shared, world-writable directories like /tmp and /var/tmp, where multiple users or processes might create temporary files without risking interference from others. As of 2025, this directory-specific behavior remains consistently implemented across major systems, including distributions such as and , where it is commonly set to mode 1777 for /tmp in compliance with practices for securing world-writable directories as per the (FHS), which requires /tmp to be world-writable. Similarly, macOS on APFS supports the sticky bit for directories, treating them as append-only in terms of deletion to safeguard shared spaces. In the BSD family—, , and —the sticky bit enforces the same restrictions, ensuring that unprivileged users cannot remove or rename files they do not own within such directories. The primary security benefit of the sticky bit on directories arises in multi-user environments, such as web servers or shared hosting setups, where it mitigates risks like symlink attacks; by preventing unauthorized deletion or renaming, it blocks attackers from replacing legitimate with malicious symlinks that could exploit time-of-check-to-time-of-use (TOCTOU) vulnerabilities in privileged processes. This protection is essential for maintaining in collaborative file systems without overly restricting usability. However, the sticky bit has notable limitations: it does not inhibit the creation of new files or the modification of existing ones within the , focusing solely on unlink and rename operations to balance security with necessary flexibility.

On Files

In early Unix systems, the sticky bit set on files directed the operating system to retain the program's text image in swap space following execution, thereby accelerating subsequent invocations by avoiding full reloads from disk. This behavior was specific to executables and had no effect on non-executable regular files, where the bit was simply ignored. In contemporary implementations, the sticky bit on regular files is ignored across major systems, exerting no influence on file operations or performance. For instance, in , it holds no functional significance for files beyond its display in permission listings. Similarly, macOS disregards the bit when applied to regular files, treating it as obsolete. Most BSD variants, including and , follow suit, with the bit ignored for non-directory file types. Rare vestiges of file-specific sticky bit functionality persisted in certain systems into the early . Prior to its removal in around 2005, the bit on non-executable files—particularly swap files—signaled the to bypass caching, preserving system memory by preventing these files from displacing other data in the . Due to its lack of effect in modern environments, setting the sticky bit on regular files is not recommended, as it provides no operational benefit and could mislead administrators or tools interpreting permission flags.

Examples

Command-Line Operations

The sticky bit on directories can be set using the command in systems, primarily through symbolic or notation. To set it symbolically, the command chmod +t <directory> is used, which appends the sticky bit to the existing permissions without altering other access rights. For notation, chmod 1777 <directory> applies read, write, and execute permissions to owner, group, and others, while setting the sticky bit (represented by the leading '1' in the four-digit mode, yielding rwxrwxrwt). These operations require appropriate privileges; for directories owned by the user, no elevated permissions like are needed, but root access may be required otherwise. To unset the sticky bit, the symbolic mode chmod -t <directory> removes it while preserving other permissions. Alternatively, in mode, chmod 0777 <directory> clears the sticky bit by omitting the leading '1', resulting in rwxrwxrwx permissions. As with setting, ownership determines if [sudo](/page/Sudo) is necessary for the change. For applying the sticky bit recursively to a directory and its subdirectories, the -R flag is used with chmod -R +t <path/to/dir>, which propagates the change through the entire hierarchy. The octal equivalent, chmod -R 1777 <path/to/dir>, achieves the same recursive effect. Caution is advised with recursive operations, as they affect all nested items unless ownership restricts execution. Verification of the sticky bit's status is performed using ls -ld <directory>, which displays the directory's permissions in long format; a 't' in the permissions string (e.g., drwxrwxrwt) indicates the bit is set. This command requires no special privileges for directories owned by the user.

Permission Display

In Unix-like systems, the sticky bit's presence in file permissions is commonly inspected using command-line tools that display file metadata in either symbolic or octal notation. The ls command, when invoked with the -l option for long format, reveals the sticky bit through specific symbols in the permission string. For directories where the sticky bit is set and the execute permission for others is granted, a lowercase 't' appears in the execute position of the others' permissions (e.g., drwxrwxrwt). If the execute permission for others is absent but the sticky bit is set, an uppercase 'T' is used instead (e.g., drwxrwxrwT). This notation replaces the standard 'x' or '-' in the ninth position of the 10-character permission field. The command provides a more numerical view of permissions, including the sticky bit, by outputting the file mode in format. Using the --format or -c option with the %a specifier (e.g., stat -c '%a %n' filename), the command displays the full octal value, where the sticky bit contributes the leading '1' in a four-digit mode (e.g., 01777 for a directory with full permissions and the sticky bit set). This octal representation encodes special bits like the sticky bit (value ) alongside standard read/write/execute permissions, allowing precise interpretation without symbolic mapping. To locate files or directories with the sticky bit set across a filesystem, the find command employs the -perm test with mode specification. The expression -perm -1000 matches items where the sticky bit is enabled, as the leading '1' in the mode signifies this flag; the '-' prefix requires all specified bits to be set. Alternatively, -perm /1000 matches if any bits in 1000 are set, though -perm -1000 is more precise for exact sticky bit detection (e.g., find /path -type d -perm -1000). This utility is particularly useful for auditing shared directories like /tmp. In graphical user interfaces, such as GNOME's on or Apple's Finder on macOS, the sticky bit is not prominently displayed in default file listings or property dialogs, which typically show only basic symbolic permissions (e.g., rwxrwxrwx). Access to the sticky bit requires viewing extended properties or integrating terminal output, as standard views omit special bits like 't' for clarity in non-technical workflows. For instance, in Finder's Get Info window, permissions appear in symbolic form without explicit sticky bit indicators, necessitating command-line verification for confirmation.

References

  1. [1]
    Filesystems - CS 341
    Sticky bits were a bit that could be set on an executable file that would allow a program's text segment to remain in swap even after the end of the program's ...
  2. [2]
    [PDF] CHAPTER 25 - Duke People
    The. "sticky bit." In older UNIX operating systems, the sticky bit was used to write a file. (program) to memory so it would load more quickly when invoked ...
  3. [3]
    Br. David's notes on UNIX system administration
    Sticky bit: This used to be used on ordinary files to tell UNIX to keep the program in memory after it completed. This was done on often-used programs so that ...<|control11|><|separator|>
  4. [4]
    Sticky Bit (System Administration Guide: Security Services)
    Sticky Bit. The sticky bit is a permission bit that protects the files within a directory. If the directory has the sticky bit set, a file can be deleted ...
  5. [5]
    Special File Permissions (setuid, setgid and Sticky Bit)
    Three special types of permissions are available for executable files and public directories: setuid, setgid, and sticky bit.
  6. [6]
    ls(1) - Linux manual page
    ### Summary: Special Permissions (Sticky Bit) in Long Listing Format
  7. [7]
    stat(2) - Linux manual page
    ### Summary of Sticky Bit in stat Structure
  8. [8]
    Linux permissions: SUID, SGID, and sticky bit - Red Hat
    Oct 15, 2020 · If set on a file, it allows the file to be executed as the group that owns the file (similar to SUID); If set on a directory, any files created ...Missing: authoritative | Show results with:authoritative
  9. [9]
    Linux Sticky Bit Permission Explained - LinuxConfig
    Sep 22, 2025 · Sticky bit only allows root, directory owner and file owner to rename and delete files. How to Set Sticky Bit Permissions. Setting the sticky ...Missing: authoritative | Show results with:authoritative
  10. [10]
    Sticky Bit (System Administration Guide: Security Services)
    If the directory has the sticky bit set, a file can be deleted only by the file owner, the directory owner, or by a privileged user. The root user and the ...Missing: benefits denial service<|control11|><|separator|>
  11. [11]
    Linux File Permissions: setuid, setgid, Sticky Bit
    Sep 10, 2025 · Today, the sticky bit restricts who can delete files in a directory on Linux systems. Specifically, when the sticky bit is set, only the user ...Missing: authoritative | Show results with:authoritative
  12. [12]
    Linux Sticky Bit Concept Explained with Examples - The Geek Stuff
    Feb 26, 2013 · The sticky bit is not a new concept. In fact, it was first introduced in in 1974 in the Unix operating system. The purpose of sticky bit back ...
  13. [13]
    How does the sticky bit work? - Unix & Linux Stack Exchange
    Jun 14, 2013 · A sticky bit is a permission bit that is set on a directory that allows only the owner of the file within that directory or the root user to ...sticky bit on files and directories - Unix & Linux Stack ExchangePermission needed to create/remove file in a directory with sticky bit ...More results from unix.stackexchange.comMissing: standard | Show results with:standard
  14. [14]
    [PDF] UNIX PROGRAMMER'S MANUAL
    Jun 11, 1974 · UNIX PROGRAMMER'S MANUAL. F~ifth ~. K. Thompson. D. M. Ritchie. June ... The text of the manual was prepared using the ed text editor. Page 3 .
  15. [15]
    [PDF] The UNIX Time- Sharing System
    July 1974 of. Volume 17 the ACM. Number 7. The UNIX Time-. Sharing System. Dennis M. Ritchie and Ken Thompson. Bell Laboratories. UNIX is a general-purpose, ...Missing: origins Fifth
  16. [16]
    [PDF] 4.3 BSD with NFS Programmer's Reference Manual PRM
    Apr 16, 1986 · This manual retlects system eDhancements made at Berkeley and sponsored in part by the Defense Advanced Research.
  17. [17]
    chmod(1) - Linux manual page - man7.org
    The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from ...Missing: deprecated | Show results with:deprecated
  18. [18]
  19. [19]
    sticky(8) - OpenBSD manual pages
    A directory with the 'sticky bit' set places restrictions on file deletion: a file in a sticky directory may only be removed or renamed by a user if the user ...Missing: dropped | Show results with:dropped
  20. [20]
    chmod - HP-UX - nix Documentation Project
    ... sticky bit of a regular file. If the sticky bit is set on a directory, files inside the directory may be renamed or removed only by the owner of the file ...
  21. [21]
    chmod - FreeBSD Manual Pages
    4.3BSD NET/2, 4.3BSD Reno, 2.11 BSD, 2.10 BSD, 2.9.1 BSD, 2.8 BSD, 386BSD ... t The sticky bit. w The write bits. x The execute/search bits. X The execute ...
  22. [22]
    inode(7) - Linux manual page - man7.org
    The following mask values are defined for the file mode component of the st_mode field ... The sticky bit (S_ISVTX) on a directory means that a file in ...
  23. [23]
  24. [24]
    chmod(2) - FreeBSD Manual Pages
    For more details of the properties of the sticky bit, see sticky(7). If mode ... Only UFS file systems support this option. For more details of the ...<|control11|><|separator|>
  25. [25]
    chmod
    ### Summary of Sticky Bit Enforcement in POSIX (chmod)
  26. [26]
    unlink(2) - Linux manual page - man7.org
    unlink() deletes a name from the filesystem. If that name was the last link to a file and no processes have the file open, the file is deleted.Missing: VFS enforcement
  27. [27]
    Overview of the Linux Virtual File System — The Linux Kernel documentation
    ### Summary on VFS Layer Enforcement of Sticky Bit for File Operations (unlink and rename)
  28. [28]
    sticky(7) - NetBSD Manual Pages
    A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, ...
  29. [29]
    unlink - man pages section 2: System Calls
    EACCES. The parent directory has the sticky bit set and the file is not writable by the user, the user does not own the parent directory, the user does not ...
  30. [30]
  31. [31]
    sticky Man Page - macOS - SS64.com
    A special file mode, called the sticky bit (mode S_ISVTX), is used to indicate special treatment for directories. It is ignored for regular files.Missing: APFS | Show results with:APFS
  32. [32]
  33. [33]
    symlink(7) - Linux manual page - man7.org
    The ownership of a symbolic link matters when the link is being removed or renamed in a directory that has the sticky ... For details of in-depth Linux/UNIX ...
  34. [34]
    SetUID, SetGID, and Sticky Bits in Linux File Permissions
    Jul 12, 2025 · When a directory has the sticky bit set, its files can be deleted or renamed only by the file owner, directory owner and the root user. The ...
  35. [35]
    sticky - FreeBSD Manual Pages
    It is ignored for regular files. See chmod(2) or the file <sys/stat.h> for ... file with the sticky bit set. FreeBSD 14.3 June 5, 1993 STICKY(7). NAME ...
  36. [36]
    sticky bit on files and directories - Unix & Linux Stack Exchange
    Nov 7, 2023 · Solaris removed it in 2005. For non-executable files, the sticky bit is used on Solaris to tell the OS that this file should not be cached.What did the sticky bit originally do when applied to files?How does the sticky bit work? - Unix & Linux Stack ExchangeMore results from unix.stackexchange.comMissing: abandoned | Show results with:abandoned
  37. [37]
    sticky - man pages section 5: Standards, Environments, and Macros
    A file in a sticky directory can only be removed or renamed by a user who has write permission on the directory, and either owns the file, owns the directory, ...
  38. [38]
    How Do I Set Up Setuid, Setgid, and Sticky Bits on Linux? - Liquid Web
    Mar 2, 2020 · Setuid, Setgid and Sticky Bits are special types of Unix/Linux file permission sets that permit certain users to run specific programs with elevated privileges.Symbolic Permission Notation · Numeric Permission Notation · What Is Setuid?Missing: authoritative | Show results with:authoritative<|control11|><|separator|>
  39. [39]
    stat(1) - Linux manual page
    ### How to Display Octal Mode with `stat`, Including Special Bits
  40. [40]
    find(1) - Linux manual page
    ### Summary of `-perm` Option for Sticky Bit (e.g., -1000)
  41. [41]
    Get file, folder, and disk information on Mac - Apple Support
    On your Mac, open a folder in the Finder or click the desktop. · Choose View > Show View Options. · Select “Show item info.” (Only available for Icon view.).Missing: sticky bit