File Permissions
The Unix scheme of read, write, and execute rights for a file's owner, group, and everyone else, and the extensions that patch its gaps.
File permissions control who can do what with each file on a Unix-like system. Every file has an owner and a group, and nine permission bits grant three rights to three classes of user:
- Read (r), write (w), and execute (x).
- For the owner, members of the file's group, and others, meaning everyone else.
ls -l shows these as a string like rwxr-x---: the owner can read, write, and execute; the group can read and execute; others have no access. They're often written in octal, with read as 4, write as 2, and execute as 1, so chmod 750 sets that same pattern and chmod 644 gives a typical document, readable by all and writable by the owner. The bits are stored in each file's Inode.
For directories, the bits mean something different. Read lets you list the names inside, write lets you create, delete, and rename entries, and execute lets you pass through the directory to reach things inside it. Because deleting a file is a change to its directory, a user who can write to a directory can delete files in it even without permission on the files themselves. The sticky bit on shared directories like /tmp closes that gap by letting only a file's owner delete it.
Two special bits change who a program runs as. Setuid on an executable makes it run with the file owner's privileges instead of the caller's. passwd is owned by root and setuid so ordinary users can update the password file. Setuid programs owned by root are a classic attack target, since any bug in one can hand an attacker full control, so modern systems keep them few. Setgid does the same for the group, and on directories makes new files inherit the directory's group.
The umask sets which permissions new files lack by default; 022 keeps them unwritable by group and others.
The basic model has well-known limits. It allows one owner and one group per file. Access control lists (ACLs) extend it with per-user and per-group entries. The root user bypasses permissions entirely, which Least Privilege designs counter by splitting root's power into finer capabilities and adding mandatory controls such as SELinux and AppArmor, which restrict even root.
Permissions cause everyday errors. A private SSH key readable by others is refused by Secure Shell as a safety measure, a script without the execute bit won't run directly, and files created inside a container as root may be unwritable by the host user, a common snag with Docker volumes. Files holding secrets usually need tight modes such as 600; see Secret Management. Every permission check is performed by the Kernel when a program opens a file through a System Call, which is what makes the scheme enforceable.
See also3
Archive File
Files that bundle many files and their metadata into one, from tape-era tar streams to zip's index at the end, whose design choices still decide what can be listed, extracted, or exploited.
Systems & Tooling6 connections
Kernel
The core of an operating system that runs with full hardware privileges, managing processes, memory, devices, and files on behalf of every other program.
Systems & Tooling24 connections
Superuser
The all-powerful root account on Unix systems, how sudo hands out its power temporarily, and why both attackers and good security design revolve around who gets it.
Systems & Tooling10 connections
Linked from9
- Archive FileSystems & Tooling
Files that bundle many files and their metadata into one, from tape-era tar streams to zip's index at the end, whose design choices still decide what can be listed, extracted, or exploited.
- Device FileSystems & Tooling
Special files that represent hardware and kernel services, letting programs read a disk, a mouse, or a stream of random bytes with the same calls they use on ordinary files.
- InodeSystems & Tooling
The record a Unix filesystem keeps about a file's metadata and data location — everything except its name.
- KernelSystems & Tooling
The core of an operating system that runs with full hardware privileges, managing processes, memory, devices, and files on behalf of every other program.
- Secure ShellSystems & Tooling
The encrypted protocol for logging into and running commands on remote machines, authenticated by key pairs, that also tunnels other traffic and underpins Git.
- ShebangSystems & Tooling
The "#!" line at the top of a script that tells the kernel which interpreter should run it, so a text file can be executed like a compiled program, and the portability traps around it.
- SuperuserSystems & Tooling
The all-powerful root account on Unix systems, how sudo hands out its power temporarily, and why both attackers and good security design revolve around who gets it.
- System CallSystems & Tooling
The doorway through which a program asks the operating system kernel to do anything privileged, from reading a file to starting a process.
- Time-of-Check to Time-of-UseSystems & Tooling
A race where a program checks a condition and then acts on it, but the world changes in between, the root of classic file-permission exploits and of double-spending bugs in web applications.