File system permissions

From Wikipedia, the free encyclopedia

Jump to: navigation, search

Most modern file systems have methods of administering permissions or access rights to specific users and groups of users. These systems control the ability of the users affected to view or make changes to the contents of the file system.


[edit] Differences between operating systems

Unix-like and otherwise POSIX-compliant systems, including Linux-based systems and all Mac OS X 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, either proprietary (old HP-UX ACLs, for example), or POSIX.1e ACLs, based on early POSIX draft that was abandoned, or NFSv4 ACLs, which are the part of NFSv4 standard.

DOS variants (including the Microsoft products MS-DOS, Windows 95, Windows 98, and Windows Me) do not have permissions. There is a "read-only" attribute that can be set or unset on a file by any user or program.

VMS and OpenVMS as well as Microsoft Windows NT and its derivatives (including Windows 2000 and Windows XP), use access control lists (ACLs)[1] to administer a more complex and varied set of permissions.

Classic Mac OSes are similar to DOS variants and DOS based Windows: they do not support permissions, but only a "Protected" file attribute.

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.

Solaris ACL support depends on the filesystem being used - older UFS filesystem supports POSIX.1e ACLs, while ZFS supports only NFSv4 ACLs.[2]

Linux supports POSIX.1e ACLs. There is experimental support for NFSv4 ACLs for ext3 filesystem.[3]

FreeBSD supports POSIX.1e ACLs. There is experimental support for NFSv4 ACLs for UFS and ZFS filesystems.[4]

[edit] Traditional Unix permissions

Permissions on Unix-like systems are managed in three distinct classes. These classes are known as user, group, and others. In effect, Unix permissions are a simplified form of access control lists (ACLs).

When a new file is created on a Unix-like system, its permissions are determined from the umask of the process that created it.

[edit] Classes

On Unix file systems, every file and directory is owned by a specific user. The owner of an object comprises its user class. Permissions assigned to the user class only apply to that specific user.

A file or directory is also assigned a group, which comprises its group class. Permissions assigned to the group class only apply to members of that group (other than the owner). It is not necessary that the owner be a member of the file's group. While a particular file can be assigned to only one group, a particular user can be a member of any number of groups, and a group can include any number of users. The "groups" command lists all the groups that include a user; the "members" command lists all the users that are the member of a particular group (Stutz 2004). The system administrator uses "addgroup" to add a user to a group.

Users who are not otherwise represented by the other two classes comprise a file's others class.

The effective permissions that have applied to a specific user in relation to a file are determined in logical precedence. For example, the user who owns the file will have the effective permissions given to the user class regardless of those assigned to the group or others class.

[edit] Basic Permissions

There are three specific permissions on Unix-like systems that apply to each class:

  • The read permission, which 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, including file type, size, ownership, permissions, etc.)
  • The write permission, which grants the ability to modify a file. When set for a directory, this permission grants the ability to modify entries in the directory. This includes creating files, deleting files, and renaming files.
  • The execute permission, which grants the ability to execute a file. This permission must be set for executable binaries (for example, a compiled c++ program) or shell scripts (for example, a Perl program) in order to allow the operating system to run them. When set for a directory, this permission grants the ability to traverse its tree in order to access files or subdirectories, but not see files inside the directory (unless read is set).

The effect of setting the permissions on a directory (rather than a file) is "one of the most frequently misunderstood file permission issues" (Hatch 2003).

When a permission is not set, the rights it would grant are denied. Unlike ACL-based systems, permissions on a Unix-like system are not inherited. Files created within a directory will not necessarily have the same permissions as that directory. The permissions to be assigned are determined using umasks.

[edit] Additional Permissions

Unix-like systems typically employ three additional permissions or modes. These special permissions are set for a file or directory overall, not by a class.

  • The set user ID, setuid, or SUID permission. When a file for which this permission has been set is executed, the resulting process will assume the effective user ID given to the user class.
  • The set group ID, setgid, or SGID permission. When a file for which this permission has been set 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 the 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.)
  • The sticky permission. The typical behaviour of the sticky bit on executable files encourages the kernel to retain the resulting process image beyond termination. 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 permissions are also referred to as setuid bit, setgid bit, and sticky bit respectively, due to the fact that they each occupy only one bit.

[edit] Notation of traditional Unix permissions

[edit] Symbolic notation

There are many ways by which Unix permission schemes are represented. The most common form is symbolic notation. This scheme represents permissions as a series of 10 characters.

First Character
- a regular file
d a directory
l a symbolic link
Three groups of three
first what the owner can do
second what the group members can do
third what other users can do
The triplet
first r: readable.
second w: writable.
third x: executable.
other: see below.

The first character indicates the file type:

Each class of permissions is represented by three characters. The first set of characters represents the user class. The second set represents the group class. The third and final set of three characters represents the others class.

Each of the three characters represent the read, write, and execute permissions respectively:

  • r if the read bit is set, - if it is not.
  • w if the write bit is set, - if it is not.
  • x if the execute bit is set, - if it is not.
  • The x will be an s if the setuid or setgid bit is also set, and in the third, it will be a t if the sticky bit is set. If these are set but the execute bit is not, the letter will be in uppercase.

The following are some examples of symbolic notation:

  • -rwxr-xr-x for 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-- for 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------ for a directory whose user class has read and execute permissions and whose group and others classes have no permissions.

[edit] Symbolic notation and additional permission

The three additional permissions are indicated by changing one of the three "execute" characters as shown in the following table:

Permission Class Executable1 Non-executable2
Set User ID (setuid) User s S
Set Group ID (setgid) Group s S
Sticky bit Others t T
  1. The character that will be used to indicate that the execute bit is also set.
  2. The character that will be used when the execute bit is not set.

Here is an example:

  • "-rwsr-Sr-x" for 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 and setgid permissions set.

[edit] Octal notation

Another common method for representing Unix permissions is octal notation. Octal notation consists of a three- or four-digit base-8 value.

With three-digit octal notation, each numeral represents a different component of the permission set: user class, group class, and "others" class respectively.

Each of these digits is the sum of its component bits (see also 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.

These are the examples from the Symbolic notation section given in octal notation:

  • "-rwxr-xr-x" would be represented as 755 in three-digit octal.
  • "-rw-rw-r--" would be represented as 664 in three-digit octal.
  • "-r-x------" would be represented as 500 in three-digit octal.

Here is a summary of the meanings for individual octal digit values:

0 --- no permission
1 --x execute 
2 -w- write 
3 -wx write and execute
4 r-- read
5 r-x read and execute
6 rw- read and write
7 rwx read, write and execute

Octal digit values can be added together to make Symbolic Notations:
(4=r)+(1=x) == (5=r-x)
(4=r)+(2=w) == (6=rw-)
(4=r)+(2=w)+(1=x) == (7=rwx)

Here is a summary showing which octal digits affect permissions for user, group, and other:

  • UGO = User, Group, Other
  • 777 = "-rwxrwxrwx" = rwx for all
  • 754 = "-rwxr-xr--" = rwx for owner, r-x for group, r-- for other
  • 124 = "---x-w-r--" = x for owner, w for group, r for other

[edit] Octal notation and additional permissions

There is also a four-digit form of octal notation. In this scheme, the standard three digits described above become the last three digits. The first digit represents the additional permissions. On some systems, this first digit cannot be omitted; it is therefore common to use all four digits (where the first digit is zero).

This first digit is also the sum of component bits:

  • The setuid bit adds 4 to the total,
  • The setgid bit adds 2 to the total, and
  • The sticky bit adds 1 to the total.

The example from the Symbolic notation and additional permissions section, "-rwsr-Sr-x" would be represented as 6745 in four-digit octal. In addition, the examples in the previous section (755, 664, and 500) would be represented as 0755, 0664, and 0500 respectively in four-digit octal notation.

[edit] User private group

Some systems create a new group – a "user private group" – for each new user. The "user private group" scheme can be preferred for a variety of reasons[5][6][7] including using a umask of 002 and not having every "user" able to write to newly created files.

[edit] See also

[edit] References

  1. ^
  2. ^
  3. ^
  4. ^
  5. ^ Using User Private Groups - O'Reilly ONLamp Blog
  6. ^ User Private Groups
  7. ^ 32.5. User Private Groups

[edit] External links

Personal tools