# chmod u+s: The Setuid Bit Explained

> Sets setuid: the program runs with its owner's privileges.

A setuid executable runs as the user who owns the file, not the user who started it. That's how `passwd` (owned by root) can update `/etc/shadow` when an ordinary user changes their password.

It's also a classic privilege-escalation path: a bug in a setuid-root program can hand an attacker root. Don't set it on your own programs without a very good reason.

## What it changes

`-rwxr-xr-x` → `-rwsr-xr-x` (the s replaces the owner's x)

## Examples

```
ls -l /usr/bin/passwd
```

a real setuid program: -rwsr-xr-x root root

```
chmod u+s program
```

set it

```
chmod 4755 program
```

the same as a full numeric mode

```
find / -perm -4000 -type f 2>/dev/null
```

list every setuid file on the system — a standard security check

## Good to know

- Linux ignores setuid on interpreted scripts (anything started through a `#!` line). Only compiled executables honor it.
- Filesystems mounted `nosuid` ignore the bit entirely.
- Changing a file's owner or group with chown clears setuid, so set it after chown, not before.
- A capital `S` in `ls -l` means setuid is set but the owner can't execute the file — almost always a mistake.

## FAQ

### What does chmod u+s do?

It sets the setuid bit. When the file is executed, the process runs with the file owner's user ID instead of the caller's.

### Does setuid work on shell scripts?

No. Linux ignores the setuid bit on scripts run through a `#!` interpreter, because it was too easy to exploit. Use sudo with a narrow rule instead.

### How do I find setuid files?

`find / -perm -4000 -type f 2>/dev/null` lists them. Unexpected entries in that list are worth investigating.

## Related

- [chmod 4755](https://www.devkult.com/chmod/4755.md)
- [chmod 755](https://www.devkult.com/chmod/755.md)
- [chmod g+s](https://www.devkult.com/chmod/g-plus-s.md)
- [chmod +t](https://www.devkult.com/chmod/plus-t.md)

Open the interactive page: https://www.devkult.com/chmod/u-plus-s