<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sticky-Bit on K-Life Hack | Systems Architecture &amp; DevOps</title><link>https://klifehack.com/en/tags/sticky-bit/</link><description>Recent content in Sticky-Bit on K-Life Hack | Systems Architecture &amp; DevOps</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Sun, 23 Aug 2026 10:10:08 +0900</lastBuildDate><atom:link href="https://klifehack.com/en/tags/sticky-bit/index.xml" rel="self" type="application/rss+xml"/><item><title>Kernel Operation and Privilege Control of Special Permissions (SetUID, SetGID, Sticky Bit) in Linux</title><link>https://klifehack.com/en/p/linux-special-permissions-setuid-setgid-stickybit/</link><pubDate>Sun, 23 Aug 2026 10:10:08 +0900</pubDate><guid>https://klifehack.com/en/p/linux-special-permissions-setuid-setgid-stickybit/</guid><description>&lt;p&gt;When multiple users share and operate on a single system resource in a Linux environment, standard permission structures (rwx for Owner/Group/Others) alone cannot achieve delegation of privileged operations or secure access control within directories. For example, when a regular user changes their own password, they need to update the &lt;code&gt;/etc/shadow&lt;/code&gt; file, which normally only root has write permission to. To meet such operational requirements, the Linux kernel incorporates special permission bits (SetUID, SetGID, Sticky Bit) inside the 16-bit file mode structure (&lt;code&gt;st_mode&lt;/code&gt;).&lt;/p&gt;&#10;&lt;h2 id="structure-of-st_mode-16-bit-integer-mask"&gt;Structure of st_mode (16-bit Integer Mask)&#10;&lt;/h2&gt;&lt;p&gt;In a file system, permission information is stored as the &lt;code&gt;st_mode&lt;/code&gt; structure (16-bit integer) inside the inode. When an administrator executes a command like &lt;code&gt;chmod 755&lt;/code&gt;, it is evaluated inside the kernel as four digits (&lt;code&gt;0755&lt;/code&gt;), including the omitted leading octal digit.&lt;/p&gt;&#10;&lt;pre tabindex="0"&gt;&lt;code&gt;+-------------------+----------------------+---------------------------------------+&#10;| File Type Bitmask | Special Bits Bitmask | Standard Permission Bitmask (9 bits) |&#10;| (4 bits) | (3 bits) | User (3b) | Group (3b) | Others (3b) |&#10;+-------------------+----------------------+-----------+------------+--------------+&#10;| Bit 15 - Bit 12 | Bit 11 - Bit 9 | Bit 8 - 6 | Bit 5 - 3 | Bit 2 - 0 |&#10;+-------------------+----------------------+-----------+------------+--------------+&#10;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;b&gt;File Type Bitmask (Bit 15–12)&lt;/b&gt;:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;code&gt;-&lt;/code&gt; : Regular File&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;d&lt;/code&gt; : Directory&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;c&lt;/code&gt; : Character Device&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;b&lt;/code&gt; : Block Device&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;s&lt;/code&gt; : Socket&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;l&lt;/code&gt; : Symbolic Link&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;p&lt;/code&gt; : Named Pipe (FIFO)&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Special Permission Bitmask (Bit 11–9)&lt;/b&gt;:&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Bit 11 (04000)&lt;/b&gt; : SetUID&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Bit 10 (02000)&lt;/b&gt; : SetGID&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Bit 9 (01000)&lt;/b&gt; : Sticky Bit&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Standard Permission Bitmask (Bit 8–0)&lt;/b&gt;:&lt;/li&gt;&#10;&lt;li&gt;&lt;code&gt;rwx&lt;/code&gt; bits assigned to Owner / Group / Others respectively&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="setuid-set-user-id---octal-4000"&gt;SetUID (Set User ID - Octal 4000)&#10;&lt;/h2&gt;&lt;p&gt;When a binary executable with SetUID set is executed, the kernel escalates the process execution privileges (Effective User ID: EUID) to the owner ID of the file instead of the user who launched the command (Real User ID: RUID).&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod &lt;span style="color:#ae81ff"&gt;4755&lt;/span&gt; executable_file&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# or&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod u+s executable_file&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In the notation of &lt;code&gt;ls -l&lt;/code&gt; output, it is displayed in the owner&amp;rsquo;s execute permission (&lt;code&gt;x&lt;/code&gt;) position. If execute permission is granted, it is displayed as a lowercase &lt;code&gt;s&lt;/code&gt; (&lt;code&gt;-rwsr-xr-x&lt;/code&gt;); if execute permission is missing, it is displayed as an uppercase &lt;code&gt;S&lt;/code&gt; (&lt;code&gt;-rwSr-xr-x&lt;/code&gt;).&lt;/p&gt;&#10;&lt;p&gt;&lt;code&gt;/usr/bin/passwd&lt;/code&gt; is a typical application of SetUID. Even when executed by a regular user, the EUID is temporarily changed to &lt;code&gt;root&lt;/code&gt; while the process is running, enabling updates to the privileged file &lt;code&gt;/etc/shadow&lt;/code&gt;.&lt;/p&gt;&#10;&lt;h2 id="setgid-set-group-id---octal-2000"&gt;SetGID (Set Group ID - Octal 2000)&#10;&lt;/h2&gt;&lt;p&gt;SetGID operates on group ownership for files and directories.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;b&gt;Application to executables&lt;/b&gt;: Changes the Effective Group ID (EGID) of the process to the file&amp;rsquo;s owner group ID at execution time.&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;Application to directories&lt;/b&gt;: Forces all files and subdirectories newly created within the directory to inherit the owner group ID of the parent directory, rather than the primary group of the creator.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod &lt;span style="color:#ae81ff"&gt;2775&lt;/span&gt; shared_directory&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Or&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod g+s shared_directory&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It is widely used in configurations where write permissions for newly generated files are inherited by a specific service group (such as the &lt;code&gt;mail&lt;/code&gt; group), as seen in the &lt;code&gt;/var/mail&lt;/code&gt; directory (&lt;code&gt;drwxrwsr-x&lt;/code&gt;).&lt;/p&gt;&#10;&lt;h2 id="sticky-bit-octal-1000"&gt;Sticky Bit (Octal 1000)&#10;&lt;/h2&gt;&lt;p&gt;The Sticky Bit (Restricted Deletion Flag) is a flag that restricts users from unintentionally (or maliciously) deleting or renaming files created by others in a shared directory where all users have write permissions (&lt;code&gt;777&lt;/code&gt;).&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod &lt;span style="color:#ae81ff"&gt;1777&lt;/span&gt; shared_tmp&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Or&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod +t shared_tmp&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In a directory with the Sticky Bit set, only users who fall under one of the following can delete or rename files:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Owner of the file&lt;/li&gt;&#10;&lt;li&gt;Owner of the parent directory&lt;/li&gt;&#10;&lt;li&gt;Superuser (&lt;code&gt;root&lt;/code&gt;)&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;The &lt;code&gt;/tmp&lt;/code&gt; directory (&lt;code&gt;drwxrwxrwt&lt;/code&gt;) is a prime example of this setting.&lt;/p&gt;&#10;&lt;h2 id="kernel-level-process-identifiers"&gt;Kernel-Level Process Identifiers&#10;&lt;/h2&gt;&lt;p&gt;When executing a process, the Linux kernel maintains the following identifiers for privilege verification:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;b&gt;PID (Process ID)&lt;/b&gt;: Unique identifier of the process&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;RUID (Real User ID)&lt;/b&gt;: Actual user ID that launched the process&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;EUID (Effective User ID)&lt;/b&gt;: User ID referenced by the kernel for access permission determination during resource access&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;RGID (Real Group ID)&lt;/b&gt;: Primary group ID of the user that launched the process&lt;/li&gt;&#10;&lt;li&gt;&lt;b&gt;EGID (Effective Group ID)&lt;/b&gt;: Group ID referenced by the kernel during access permission determination&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;SetUID / SetGID achieve privilege escalation by temporarily swapping these EUID / EGID values.&lt;/p&gt;&#10;&lt;h2 id="troubleshooting"&gt;Troubleshooting&#10;&lt;/h2&gt;&lt;h3 id="1-disabling-privilege-escalation-via-the-nosuid-mount-option"&gt;1. Disabling Privilege Escalation via the &lt;code&gt;nosuid&lt;/code&gt; Mount Option&#10;&lt;/h3&gt;&lt;p&gt;⚠️ If a Permission Denied error occurs at execution time despite the SetUID/SetGID flags (e.g., &lt;code&gt;4755&lt;/code&gt;) being correctly set on the file, the corresponding file system may be mounted with the &lt;code&gt;nosuid&lt;/code&gt; option.&lt;/p&gt;&#10;&lt;p&gt;On a partition where &lt;code&gt;nosuid&lt;/code&gt; is enabled, the kernel completely ignores SetUID and SetGID bits for safety reasons.&lt;/p&gt;&#10;&lt;p&gt;💡 Verification and resolution flow:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ findmnt -n -o OPTIONS -T /path/to/binary&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;rw,nosuid,nodev,relatime&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If &lt;code&gt;nosuid&lt;/code&gt; is included in the output above, you need to allow &lt;code&gt;exec,suid&lt;/code&gt; by modifying the &lt;code&gt;/etc/fstab&lt;/code&gt; configuration or manually remounting.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sudo mount -o remount,suid /path/to/mountpoint&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="2-display-issues-with-uppercase-s-or-t-flags"&gt;2. Display Issues with Uppercase &lt;code&gt;S&lt;/code&gt; or &lt;code&gt;T&lt;/code&gt; Flags&#10;&lt;/h3&gt;&lt;p&gt;⚠️ When executing the &lt;code&gt;ls -l&lt;/code&gt; command displays uppercase letters such as &lt;code&gt;-rwSr-xr-x&lt;/code&gt; or &lt;code&gt;drwxrwxr-T&lt;/code&gt;, special permissions (SetUID/SetGID/Sticky Bit) are set, but the corresponding execute permissions (&lt;code&gt;x&lt;/code&gt;) are not granted. In this state, privileged execution and proper directory traversal will not function.&lt;/p&gt;&#10;&lt;p&gt;🛠️ Resolution steps (re-granting execute permission):&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Fix uppercase S in SetUID&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod u+x /path/to/binary&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Fix uppercase T in Sticky Bit&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;chmod o+x /path/to/directory&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="audit-and-verification-command-logs"&gt;Audit and Verification Command Logs&#10;&lt;/h2&gt;&lt;p&gt;💡 Terminal execution examples for checking the configuration status of special permissions within the system.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ls -ld /usr/bin/passwd /var/mail /tmp&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;-rwsr-xr-x. 1 root root 68208 Jul 16 2022 /usr/bin/passwd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;drwxrwsr-x. 2 root mail 4096 Aug 23 10:00 /var/mail&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;drwxrwxrwt. 15 root root 4096 Aug 23 10:00 /tmp&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ find /usr/bin /usr/sbin -perm -4000 -type f -ls&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 68208 68 -rwsr-xr-x 1 root root 68208 Jul 16 2022 /usr/bin/passwd&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;140521 144 -rwsr-xr-x 1 root root 147280 Jan 18 2024 /usr/bin/sudo&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;210943 52 -rwsr-xr-x 1 root root 51832 Feb 4 2024 /usr/bin/chfn&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ find /var -perm -2000 -type d -ls&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; 10482 4 drwxrwsr-x 2 root mail 4096 Aug 23 10:00 /var/mail&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ findmnt -t ext4,xfs,tmpfs&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;TARGET SOURCE FSTYPE OPTIONS&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/ /dev/sda1 xfs rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/tmp tmpfs tmpfs rw,nosuid,nodev,seclabel&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="configuration-notes"&gt;Configuration Notes&#10;&lt;/h2&gt;&lt;ul&gt;&#10;&lt;li&gt;🛠️ &lt;b&gt;Minimizing SetUID&lt;/b&gt;: Assigning SetUID to unnecessary binaries leads to local privilege escalation vulnerabilities. Perform system audits regularly by running &lt;code&gt;find / -perm -4000&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;💡 &lt;b&gt;Migration to Capabilities&lt;/b&gt;: On modern Linux systems, instead of SetUID which grants root privileges to the entire binary, using Linux Capabilities (&lt;code&gt;setcap&lt;/code&gt; command) to grant only the minimum required privileges (e.g., &lt;code&gt;CAP_NET_BIND_SERVICE&lt;/code&gt;) is recommended.&lt;/li&gt;&#10;&lt;li&gt;⚠️ &lt;b&gt;Sticky Bit and Shared Directories&lt;/b&gt;: When sharing network file systems such as NFS, ensure that client-side mount settings and UID/GID mappings are configured accurately.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;</description></item></channel></rss>