Special permission bits and umask
setuid, setgid and the sticky bit: how passwd edits a root-owned file, how shared directories keep their group, why /tmp is safe, and what umask does.
Special permission bits and umask
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- chown changes a file's owner and only root may do it; the owner may chgrp a file to any group they belong to. Changing ownership of an executable clears its setuid and setgid bits.
- setuid on a program (the s in rws, octal 4000) makes it run with the file owner's identity. That is how passwd and sudo, owned by root, can do root's work for ordinary users.
- setgid on a program (2000) runs it with the file's group; on a directory it makes new files inherit the directory's group, which is what makes shared team directories work.
- The sticky bit on a directory (1000, the t in /tmp's drwxrwxrwt) lets only a file's owner, the directory's owner or root delete or rename it.
- umask removes permission bits from new files and directories. 022 gives 644 and 755, 077 gives 600 and 700. It is a per-process setting, set at login by the shell or by pam_umask from login.defs.
Where the nine bits run out
The permissions lesson in shell-bash covered rwx for owner, group and others, and chmod. Those nine bits answer “who may read, write or run this file?” They cannot answer three questions every multi-user system has:
- How does an ordinary user change their own password, when the password file is readable only by root?
- How does a team share a directory so that everyone’s new files belong to the team?
- How can
/tmpbe writable by everyone without everyone being able to delete everyone else’s files?
Three more bits answer them: setuid, setgid and the sticky bit. Before them, two commands they depend on.
chown and chgrp
chown alice:devs file sets owner and group; chgrp devs file sets just the group. The chown(2) man page sets the rules: “Only a privileged process … may change the owner of a file. The owner of a file may change the group of the file to any group of which that owner is a member.” That stops users from giving files away to dodge quotas or to plant files under someone else’s name.
It adds a safety rule that matters below: “When the owner or group of an executable file is changed by an unprivileged user, the S_ISUID and S_ISGID mode bits are cleared”, and since Linux 2.2.13 root is treated the same way. So a careless chown silently removes setuid.
setuid: borrowing the owner’s identity
When a program file has the setuid bit, execve(2) changes “the effective user ID of the calling process … to that of the owner of the program file”. A root-owned setuid program runs with root’s powers no matter who starts it. In a listing the owner’s x becomes s; in octal it is 4000.
This answers question 1. I read the permissions recorded in the official Debian 13 and Fedora 45 image archives, downloaded on a Mac:
debian -rwsr-xr-x root root /usr/bin/passwd
debian -rwsr-xr-x root root /usr/bin/su
fedora ---s--x--x root root /usr/bin/sudo
passwd runs as root, so it can rewrite /etc/shadow, and its own code makes sure you only change your own password. Every setuid-root program is a place where a bug becomes a root exploit, so distributions keep the list short. The kernel ignores the bits in risky situations: execve(2) lists a filesystem “mounted nosuid” and processes with no_new_privs set, among others. That is why /tmp and removable media are often mounted nosuid.
setgid: on programs and on directories
On a program, setgid (2000, s in the group position) does the same with the group. Debian uses it to keep root out of the picture where it can:
debian -rwxr-sr-x root shadow /usr/bin/chage
debian -rwxr-sr-x root shadow /usr/sbin/unix_chkpwd
fedora -rwsr-xr-x root root /usr/bin/unix_chkpwd
Debian’s /etc/shadow is group-readable by shadow, as the account files lesson showed, so a password checker that only needs to read it can run setgid shadow instead of setuid root. Fedora made the opposite choice.
On a directory, setgid means something different, and this is the everyday use. inode(7) says files created there “inherit their group ID from the directory, not from the effective group ID of the creating process, and directories created there will also get the S_ISGID bit set”. That answers question 2:
sudo chgrp devs /srv/project
sudo chmod 2775 /srv/project # rwxrwsr-x: setgid, group-writable
Every new file now belongs to devs. Pair it with a umask of 002 so new files are group-writable, or with a default ACL, from the next lesson.
The sticky bit
On a directory, the sticky bit (1000, t in the others position) means, per inode(7), “a file in that directory can be renamed or deleted only by the owner of the file, by the owner of the directory, and by a privileged process”. That is question 3. All four images record /tmp as drwxrwxrwt: anyone may create files, nobody may remove someone else’s. On regular files the bit is a relic: GNU chmod(1) says only that “on some older systems” it kept a program’s text in swap.
An uppercase S or T in a listing means the special bit is set but the underlying execute bit is not, which is usually a mistake.
umask: the default permissions
Programs ask for generous modes when they create things, usually 666 for files and 777 for directories. The umask takes bits away. umask(2) puts it simply: “permissions in the umask are turned off from the mode argument”. It is per process and inherited by children.
I tried three values on this Mac, which follows the same POSIX rule (macOS output, not Linux):
$ (umask 022; touch f022; mkdir d022)
$ (umask 077; touch f077; mkdir d077)
$ (umask 002; touch f002; mkdir d002)
$ ls -ld f0* d0*
drwxrwxr-x d002
drwxr-xr-x d022
drwx------ d077
-rw-rw-r-- f002
-rw-r--r-- f022
-rw------- f077
022 is the common default. 077 suits a private account or a service handling secrets. 002 suits shared group directories. One exception: if the parent directory has a default ACL, umask(2) says “the umask is ignored” and the ACL decides.
Where is it set? Per user, in a shell startup file. System-wide, it varies. Fedora’s and Ubuntu’s /etc/login.defs contain UMASK 022; Debian 13’s does not, and its /etc/pam.d/common-session loads pam_umask, which, per its man page, looks for a umask= in the user’s GECOS field, then a module argument, then UMASK in /etc/login.defs. Services started by systemd use the unit’s UMask= setting instead, which the services group covers.
About the video
The embed is WhiteboardDoodles’s “Linux File Permissions: chmod, umask & ACLs Explained”, April 2026, clipped to the “Ownership & groups”, “Special permission bits” and “Default permissions & umask” chapters (about 6 minutes). It is an animated whiteboard explanation, short on terminal demos, which is why this lesson shows real file modes from distribution images. I judged it from the chapters and description, and English from the original English audio track. Caleb Curry’s ten-minute terminal walkthrough of umask and special permissions is in deeper.
What was run: reading permission bits from the downloaded Debian, Ubuntu and Fedora image archives, and the umask experiment on macOS. Rules are quoted from chown(2), execve(2), inode(7), umask(2) and Debian’s pam_umask(8), checked 2026-11-28.
Check yourself
/usr/bin/passwd shows -rwsr-xr-x root root. Why can a normal user use it to change /etc/shadow, which they cannot read?
The s in the owner's execute position is the setuid bit. Running passwd gives the process root's effective user ID, so it can update /etc/shadow, and the program itself limits what the user may change.
A team shares /srv/project, owned by group devs, but new files keep getting each user's own primary group. What fixes it?
Set the setgid bit on the directory (chmod g+s /srv/project, octal 2xxx). New files and subdirectories then inherit the directory's group, devs.
Why can't one user delete another user's files in /tmp, even though /tmp is world-writable?
/tmp has the sticky bit (drwxrwxrwt). In a sticky directory only the file's owner, the directory's owner or root may delete or rename a file.
With a umask of 027, what modes do a new file and a new directory get?
640 for a file (666 minus 027 rounded to the bits) and 750 for a directory (777 with 027 removed).
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.