File system permissions
Most file systems have methods to assign permissions or access rights to specific users and groups of users. These permissions control the ability of the users to view, change, navigate, and execute the contents of the file system.
Two types of permissions are very widely used: traditional Unix permissions date back many decades to the earliest days of Unix. They are universally available on all Unix and Linux derived platforms. Access Control Lists (ACLs) are more recent in origin and are universally used on Microsoft Windows based file systems where the file system supports user permissions (mainly NTFS and ReFS), and are also now commonly used and widely available in most common Unix and Linux based systems, although not necessarily all. They are generally capable of far more detailed fine-tuning of permissions than the traditional Unix permissions, and permit a system of access control which traditional ACLs cannot provide. On Unix and Linux based systems, the standard type of ACL is that defined by the POSIX standard (POSIX ACLs) but other variants exist such as NFS v3 and v4 ACLs, which work slightly differently (NFSv3 ACLs or NFSv4 ACLs).
Where multiple systems are available within the same operating system, there is usually a way to specify which will be used for any given file system, and how the system should handle attempts to access or modify permissions that are controlled by one of these, using commands designed for another. The usual solution is to ensure at least some degree of awareness and inter-operability between the different commands and methods.
Operating system variationsEdit
Unix-like and otherwise POSIX-compliant systems, including Linux-based systems and all macOS versions, have a simple system for managing individual file permissions, which in this article are called "traditional Unix permissions". Most of these systems also support some kind of access control lists (ACLs), either proprietary (old HP-UX ACLs, for example), or POSIX.1e ACLs, based on an early POSIX draft that was withdrawn in 1997, or NFSv4 ACLs, which are part of the NFSv4 standard.
Microsoft and IBM DOS variants (including MS-DOS, PC DOS, Windows 95, Windows 98, Windows 98 SE, and Windows ME) do not have permissions, only file attributes. There is a read-only attribute (R), which can be set or unset on a file by any user or program, and therefore does not prevent anyone from changing/deleting the file. There is no permission in these systems which would prevent a user from reading a file.
Other MS-DOS/PC DOS-compatible operating systems such as DR DOS 3.31 and higher, PalmDOS, Novell DOS and OpenDOS, FlexOS, 4680 OS, 4690 OS, Concurrent DOS, Multiuser DOS, Datapac System Manager and IMS REAL/32 support read/write/execute/delete file/directory access permissions on FAT volumes. With the exception of FlexOS, 4680 OS, and 4690 OS all these operating systems also support individual file/directory passwords. All operating systems except for DR DOS, PalmDOS, Novell DOS and OpenDOS also support three independent file/directory ownership classes world/group/owner, whereas the single-user operating systems DR DOS 6.0 and higher, PalmDOS, Novell DOS and OpenDOS only support them with an optional multi-user security module (SECURITY.BIN) loaded.
OpenVMS (a.k.a. VMS), as well as Microsoft Windows NT and its derivatives (including Windows 2000 and Windows XP), use ACLs to administer a more complex and varied set of permissions. OpenVMS also uses a permission scheme similar to that of Unix, but more complex. There are four categories (System, Owner, Group, and World) and four types of access permissions (Read, Write, Execute and Delete). The categories are not mutually disjoint: World includes Group which in turn includes Owner. The System category independently includes system users (similar to superusers in Unix).
Classic Mac OS operating systems' HFS do not support permissions, only file attributes: "Hidden" (does not show in directory listings); "Locked" (read-only); "Name locked" (cannot be renamed); and "Stationery" (copy-on-write).
The AmigaOS Filesystem, AmigaDOS supports a relatively advanced permissions system, for a single-user OS. In AmigaOS 1.x, files had Archive, Read, Write, Execute and Delete (collectively known as ARWED) permissions/flags. In AmigaOS 2.x and higher, additional Hold, Script, and Pure permissions/flags were added.
Mac OS X versions 10.3 ("Panther") and prior use POSIX-compliant permissions. Mac OS X, beginning with version 10.4 ("Tiger"), also support the use of NFSv4 ACLs. They still support "traditional Unix permissions" as used in previous versions of Mac OS X, and the Apple Mac OS X Server version 10.4+ File Services Administration Manual recommends using only traditional Unix permissions if possible. It also still supports the Mac OS Classic's "Protected" attribute.
Traditional Unix permissionsEdit
Permissions on Unix-like systems are managed in three distinct scopes or classes. These scopes are known as user, group, and others.
When a file is created on a Unix-like system, its permissions are restricted by the umask of the process that created it.
Files and directories are assigned a group, which define the file's group class. Distinct permissions apply to members of the file's group. The owner may be a member of the file's group.
Users who are not the owner, nor a member of the group, comprise a file's others class. Distinct permissions apply to others.
The effective permissions are determined based on the first class the user falls within in the order of user, group then others. For example, the user who is the owner of the file will have the permissions given to the user class regardless of the permissions assigned to the group class or others class.
Unix-like systems implement three specific permissions that apply to each class:
- The read permission grants the ability to read a file. When set for a directory, this permission grants the ability to read the names of files in the directory, but not to find out any further information about them such as contents, file type, size, ownership, permissions.
- The write permission grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory, which includes creating files, deleting files, and renaming files. Note that this requires that execute is also set; without it, the write permission is meaningless for directories.
- The execute permission grants the ability to execute a file. This permission must be set for executable programs, in order to allow the operating system to run them. When set for a directory, the execute permission is interpreted as the search permission: it grants the ability to access file contents and meta-information if its name is known, but not list files inside the directory, unless read is set also.
The effect of setting the permissions on a directory, rather than a file, is "one of the most frequently misunderstood file permission issues".
When a permission is not set, the corresponding rights are denied. Unlike ACL-based systems, permissions on Unix-like systems are not inherited. Files created within a directory do not necessarily have the same permissions as that directory.
Changing permission behavior with setuid, setgid, and sticky bitsEdit
Unix-like systems typically employ three additional modes. These are actually attributes but are referred to as permissions or modes. These special modes are for a file or directory overall, not by a class, though in the symbolic notation (see below) the setuid bit is set in the triad for the user, the setgid bit is set in the triad for the group and the sticky bit is set in the triad for others.
- The set user ID, setuid, or SUID mode. When a file with setuid is executed, the resulting process will assume the effective user ID given to the owner class. This enables users to be treated temporarily as root (or another user).
- The set group ID, setgid, or SGID permission. When a file with setgid is executed, the resulting process will assume the group ID given to the group class. When setgid is applied to a directory, new files and directories created under that directory will inherit their group from that directory. (Default behaviour is to use the primary group of the effective user when setting the group of new files and directories, except on BSD-derived systems which behave as though the setgid bit is always set on all directories (See Setuid).)
- The sticky mode. (Also known as the Text mode.) The classical behaviour of the sticky bit on executable files has been to encourage the kernel to retain the resulting process image in memory beyond termination; however such use of the sticky bit is now restricted to only a minority of unix-like operating systems (HP-UX and UnixWare). On a directory, the sticky permission prevents users from renaming, moving or deleting contained files owned by users other than themselves, even if they have write permission to the directory. Only the directory owner and superuser are exempt from this.
These additional modes are also referred to as setuid bit, setgid bit, and sticky bit, due to the fact that they each occupy only one bit.
Notation of traditional Unix permissionsEdit
Unix permissions are represented either in symbolic notation or in octal notation.
The most common form, as used by the command
ls -l, is symbolic notation.
|Three permission triads|
|first triad||what the owner can do|
|second triad||what the group members can do|
|third triad||what other users can do|
The first character of the
ls display indicates the file type and is not related to permissions. The remaining nine characters are in three sets, each representing a class of permissions as three characters. The first set represents the user class. The second set represents the group class. The third set represents the others class.
Each of the three characters represent the read, write, and execute permissions:
rif reading is permitted,
-if it is not.
wif writing is permitted,
-if it is not.
xif execution is permitted,
-if it is not.
The following are some examples of symbolic notation:
-rwxr-xr-x: a regular file whose user class has full permissions and whose group and others classes have only the read and execute permissions.
crw-rw-r--: a character special file whose user and group classes have the read and write permissions and whose others class has only the read permission.
dr-x------: a directory whose user class has read and execute permissions and whose group and others classes have no permissions.
In some permission systems additional symbols in the
ls -l display represent additional permission features:
- + (plus) suffix indicates an access control list that can control additional permissions.
- . (dot) suffix indicates an SELinux context is present. Details may be listed with the command ls -Z.
- @ suffix indicates extended file attributes are present.
To represent the setuid, setgid and sticky or text attributes, the executable character ('x' or '-') is modified. Though these attributes affect the overall file, not only users in one class, the setuid attribute modifies the executable character in the triad for the user, the setgid attribute modifies the executable character in the triad for the group and the sticky or text attribute modifies the executable character in the triad for others. For the setuid or setgid attributes, in the first or second triad, the 'x' becomes 's' and the '-' becomes 'S'. For the sticky or text attribute, in the third triad, the 'x' becomes 't' and the '-' becomes 'T'. Here is an example:
-rwsr-Sr-t: a file whose user class has read, write and execute permissions; whose group class has read permission; whose others class has read and execute permissions; and which has setuid, setgid and sticky attributes set.
Another method for representing Unix permissions is an octal (base-8) notation as shown by
stat -c %a. This notation consists of at least three digits. Each of the three rightmost digits represents a different component of the permissions: owner, group, and others. (If a fourth digit is present, the leftmost (high-order) digit addresses three additional attributes, the setuid bit, the setgid bit and the sticky bit.)
Each of these digits is the sum of its component bits in the binary numeral system. As a result, specific bits add to the sum as it is represented by a numeral:
- The read bit adds 4 to its total (in binary 100),
- The write bit adds 2 to its total (in binary 010), and
- The execute bit adds 1 to its total (in binary 001).
These values never produce ambiguous combinations; each sum represents a specific set of permissions. More technically, this is an octal representation of a bit field – each bit references a separate permission, and grouping 3 bits at a time in octal corresponds to grouping these permissions by user, group, and others.
These are the examples from the symbolic notation section given in octal notation:
|Symbolic Notation||Numeric Notation||English|
||0700||read, write, & execute only for owner|
||0770||read, write, & execute for owner and group|
||0777||read, write, & execute for owner, group and others|
||0333||write & execute|
||0555||read & execute|
||0666||read & write|
||0740||owner can read, write, & execute; group can only read; others have no permissions|
User private groupEdit
Some systems diverge from the traditional POSIX-model of users and groups, by creating a new group – a "user private group" – for each user. Assuming each user is the only member of its user private group, this scheme allows an umask of 002 to be used without allowing other users to write to newly created files in normal directories because such files are assigned to the creating user's private group. However, when sharing files is desirable, the administrator can create a group containing the desired users, create a group-writable directory assigned to the new group, and, most importantly, make the directory setgid. Making it setgid will cause files created in it to be assigned to the same group as the directory and the 002 umask (enabled by using user private groups) will ensure that other members of the group will be able to write to those files. 
- "File and Folder Permissions". Microsoft.
- "OpenVMS documentation".
- "Archived copy". Archived from the original on 2008-10-12. Retrieved 2010-05-04.CS1 maint: Archived copy as title (link)
- "NFSv4_ACLs - FreeBSD Wiki".
- "IBM Knowledge Center".
- Hatch, Bri. "Linux File Permission Confusion pt 2", "Hacking Linux Exposed", April 24, 2003, accessed July 6, 2011.
- Epstein, Brian. "The How and Why of User Private Groups in Unix". https://security.ias.edu/. Institute for Advanced Study Network Security. Retrieved 5 August 2014. External link in
- Hradílek, Jaromír. "Red Hat Enterprise Linux 7 System Administrator's Guide, 3.3.3 Creating Group Directories". https://access.redhat.com/. Red Hat. External link in
- The Linux Cookbook: Groups and How to Work in Them by Michael Stutz 2004