TutsFx logo

Linux File Permissions Explained

Special Permissions: setuid, setgid and the Sticky Bit

2 min read Last updated 46 minutes ago

Beyond the nine rwx bits there are three special ones. You will encounter them when you inspect binaries and shared directories.

The special bits at a glance

Bit Symbol in ls -l Effect
setuid s in owner slot Runs the program with the file owner's privileges
setgid s in group slot On files: runs with the group's privileges. On directories: new files inherit the directory's group
sticky t in others slot In a shared directory, only the owner (or root) can delete files

Spotting them with ls -l

bash
$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68208 ... /usr/bin/passwd

The s where an owner x would be is setuid. passwd runs with root's powers so it can write to the password database, even when you run it as a normal user.

The sticky bit looks like a t:

bash
$ ls -ld /tmp
drwxrwxrwt 20 root root ... /tmp

/tmp is writable by everyone, but the t means only the file owner can delete files there — preventing users from wiping each other's temp files.

Setting the special bits

bash
chmod u+s program     # setuid
chmod g+s shared-dir  # setgid on a directory
chmod +t shared-dir   # sticky bit

In octal, the special bits are a leading digit: setuid 4, setgid 2, sticky 1.

bash
chmod 4755 program    # setuid + rwxr-xr-x
chmod 1777 shared-dir # sticky + rwxrwxrwx (like /tmp)
!

Setuid on your own binaries is rare

Forgetting how setuid works is a classic security hole. Never set setuid on a script or a binary you do not fully control — it can escalate privileges for anyone who can run it.

The takeaway

If ls -l shows an s or a t, the file or directory is using a special permission bit. Now you know exactly what they mean and how to set — and avoid — them.

Try it

  1. ls -l /usr/bin/passwd — spot the rws in the owner triad
  2. ls -ld /tmp — spot the trailing t
  3. mkdir ~/shared && chmod +t ~/shared && ls -ld ~/shared
Share:

We value your privacy

We use cookies to enhance your browsing experience, serve personalized ads, and analyze traffic. By clicking "Accept", you consent to our use of cookies. Read our Privacy Policy to learn more.