[Next] [Previous] [Up] [Top] [Contents] [Index]
Chapter 6: The UNIX File System
The UNIX file system allows you to control read, write, and execute access to your files on the basis of user (owner), group, and other (everyone else).[27] In this section we will consider only the standard UNIX file permissions.
[Missing image]Note that in the AFS file system, file permissions are mediated by Access Control Lists (ACLs) that are set on a directory level. The standard UNIX file permissions don't apply in this case except for the owner permissions, which apply to all users. AFS file permissions are treated in section 7.6.
To determine the current permissions, use the long form of the ls command, ls -l. Referring to the example below, the nine characters immediately following the first field represent the one-bit flags known as the mode bits that control file access. A dash indicates a bit is not set, r stands for read access, w for write access, and x for execution access. The first set of three characters refer to owner permission, the middle three for group permission, and the last three for all other user classes.
|
In the example, ignoring the directory files (which have a d in position 1), the owner has rw access to the files, whereas group and others have read (r) access only.
The chmod command, which stands for change mode, is used to change access permissions of a file or directory:
% chmod mode filename ...
or
% chmod mode directory ...
In the absolute form of the mode where the level of protection is specified in octal format, mode looks like 741 or 554, for example, where each of the three octal numbers represents the sum of the permissions granted to its class: user, group, and other, in that order. The three types of permission have the values:
4 (100 octal)
2 (010 octal)
1 (001 octal)
For example, a mode of 741 means owner can read, write, and execute (4+2+1=7); group can read (4+0+0=4); and others can execute the file (0+0+1=1).
To give this permission to a file test, you would enter:
% chmod 741 test
You can use an alternate form of mode in the chmod command in which mode is a three-character field specifying an action to be taken. The action is to add or subtract one or more permissions from one or more user classes. It takes the form:
who operator permission(s)
These three positions within the field take the following characters:
represents the user class or classes; it takes any combination of u, g, o, and a for user (user is really the owner), group, other and all, respectively, where all includes the three individual classes
+ or - for adding or subtracting permissions, or = for setting a specific permission and resetting all other permissions for the specified user class(es)
any combination of r, w, and x for read, write, and execute, indicating the permissions to be permitted, denied, or reset.
Examples of the chmod command:
progs:
% chmod g-x progs
out and out1, add group read and write, and deny write to other:
% chmod g+rw,o-w out out1
myfile:
% chmod g=r myfile
[Missing image]Note that classes of users or levels of protection not specified in a command are not modified in this form of the command (with the exception that = resets other permissions).
With the umask command you can specify a mask that the system uses to set access permissions when a file is created. In order to understand umask you need to know that access permission at file creation is application-dependent. Each command or application sets a file permission in its open command.[28] The system then "subtracts" any user-defined mask, resulting in the final access permission for the file. You can set a umask by this command:
% umask [ooo]
where ooo stands for three octal digits. The user-specified "mask", ooo, has the same positional structure as described above for chmod, but specifies permissions that should be removed (disallowed).
For example, a mask of 022 removes no permissions from owner, and removes write permission from group and others. Thus a file normally created with 777 would become 755 (this would appear as rwxr-xr-x in the format put out by the command ls -l). The following command could be put in your .cshrc or .profile.
% umask 022
The meaning of permissions applied to directories is described in Section 6.6.2.
[Missing image]See section 7.6 for AFS systems.
You can grant or deny permission for directories as well as files, and protection assigned to a directory file takes precedence over the permissions of individual files in the directory.
ls command, but not to use them.
r and x directory permission. In other words, write permission to a directory allows you to alter the contents of the directory itself, but not to alter, except to remove, files in the directory (which is controlled by the file's permissions).
File access permissions of directory files are changed with the chmod command (see section 6.6.1).