SUID, SGID, sticky bit: the special permission bits

Updated November 1, 2026

Three special bits on top of plain rwx: SUID runs a file with the owner's rights, SGID runs it with the group's rights (or sets group inheritance on a directory), sticky lets only the file owner delete a file (important for /tmp).

Why the special bits exist

The usual rwxr-xr-x scheme answers the question "who can do what." But sometimes you need to let a non-root user perform a privileged operation temporarily: change their own password (a write to /etc/shadow, which only root can access), open a raw socket for ping, or mount with mount. For this, Linux adds three special bits on top of rwx.

Where they show up in ls -l

The special bits replace the x in ls -l output:

-rwsr-xr-x  root root  /usr/bin/passwd      # SUID (s in the owner-x position)
-rwxr-sr-x  root tty   /usr/bin/wall        # SGID (s in the group-x position)
drwxrwxrwt  root root  /tmp                 # sticky (t in the other-x position)

If the bit is set but there was no x, you get a capital letter (S/T): "the bit is set, but execute does not work." Usually a typo in chmod.

Numeric form in chmod: the bit goes in the fourth digit from the left:

BitValueExample
SUID4chmod 4755
SGID2chmod 2755
sticky1chmod 1777

You can add them: chmod 6755 = SUID+SGID. Text form: chmod u+s, g+s, +t.

SUID: run with the owner's rights

When you run a binary with the SUID bit, the process's effective UID becomes the UID of the file owner, not the UID of the user starting it. If the file belongs to root, the process gets root rights for the duration of its run.

ls -l /usr/bin/passwd
# -rwsr-xr-x 1 root root ... /usr/bin/passwd

User serge runs passwd, the effective UID becomes 0 (root), the write to /etc/shadow (which only root can access) is allowed, and the password changes.

Without SUID, passwd, sudo, mount, and su would not work.

Critical Linux details:

  1. SUID is ignored on scripts. The Linux kernel deliberately ignores SUID on shebang scripts because of a TOCTOU race condition: between reading the shebang and running the interpreter, the file can be swapped out. Only ELF binaries count. If you need a "root script," wrap it in a C or Go binary, or use sudo.
  1. SUID does not work on filesystems mounted with nosuid. A standard security practice is mount -o nosuid /home, /tmp. Check it with findmnt | grep nosuid.
  1. SUID is a security smell on modern systems. The modern replacement is capabilities: give a process only the one capability it needs (CAP_NET_RAW for ping instead of full root). On current distributions /usr/bin/ping is no longer SUID; it carries cap_net_raw=ep.

SGID: two different modes

On a binary, the same as SUID but for the group

Effective GID = the file's group. It is used for binaries that read a file available only to a specific group:

ls -l /usr/bin/wall
# -rwxr-sr-x root tty ...
# → wall writes to every user's tty (the tty group) without being root

On a directory, group inheritance (gid inheritance)

THIS MATTERS MORE. New files created in the directory get the directory's group, not the creator's primary group. It is used for shared folders:

sudo mkdir /srv/team
sudo chown root:devs /srv/team
sudo chmod 2775 /srv/team           # SGID + rwxrwxr-x

# Now:
cd /srv/team
touch foo.txt
ls -l foo.txt
# -rw-rw-r-- 1 serge devs ... foo.txt    ← group devs, not serge

Without SGID the files would get the user's primary group (often serge:serge), and other team members could not edit them.

Sticky bit: protection from deleting someone else's file

In a directory with rwx permissions, any user can delete any file inside it, because deletion modifies the directory, not the file. For shared folders like /tmp this is a problem: Alice can wipe out Bob's file.

The sticky bit changes the rule: only the file owner (or root) can delete a file from the directory.

ls -ld /tmp
# drwxrwxrwt 22 root root ... /tmp     ← `t` at the end = sticky

# Create a sticky directory:
sudo mkdir /shared
sudo chmod 1777 /shared

On regular files, sticky has no meaning on modern Linux. Historically it meant "keep in swap," which has been irrelevant for a long time.

Audit: find every SUID/SGID on the host

# all SUID files
sudo find / -xdev -perm -4000 -type f 2>/dev/null

# all SGID files
sudo find / -xdev -perm -2000 -type f 2>/dev/null

# SUID or SGID
sudo find / -xdev \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null

The -xdev flag keeps find from leaving the current filesystem. Important: otherwise it would descend into /proc, /sys, and NFS mounts.

Any new SUID file in production is a reason to investigate. The reference set is usually passwd, sudo, mount, umount, su, chsh, chfn, newgrp, pkexec, chage. Distro-specific ones can exist, but anything outside that list is suspicious.

Remove SUID/SGID/sticky

chmod u-s /path/to/file       # clear SUID
chmod g-s /path/to/file       # clear SGID
chmod -t /path/to/dir         # clear sticky

Or with a number: chmod 0755 explicitly resets the special bits to 0.

Commands

  • ls -l /usr/bin/passwd /usr/bin/sudo: See the SUID bit (the letter s) on classic binaries that need root
  • sudo find / -xdev -perm -4000 -type f 2>/dev/null: Every SUID binary on the root filesystem, a standard security audit
  • sudo chmod 2775 /srv/shared && sudo chown :team /srv/shared: A shared folder with SGID: new files automatically get the team group
  • sudo chmod 1777 /scratch: A sticky directory like /tmp: everyone writes, but you can delete only your own files
  • getcap /usr/bin/ping: Check capabilities, the modern replacement for SUID on system binaries

See also