Introducing UNIX and Linux |
FilesOverview |
File access controlUNIX has a flexible method of protecting files to deal with the situations we described earlier. First of all, each file on the machine divides the users of the machine into three categories:
For each of these categories of user, that user may be either given or denied the following access privileges:
If a file has read permission, it can be examined at a terminal, printed (if it is a text file), viewed by an editor, and so on. If it has write permission, the contents of the file can be changed (for example, by an editor), and the file can be overwritten or deleted. If it has execute permission, and is a binary program or a shell script, that program can be run (but copied only if it also has read permission). An example is given later on in this chapter. Access control is determined as follows. The system first of all checks to see whether the user is the owner of a file, and if so the owner permissions are used. Otherwise, it checks to see if the user is a member of the group allocated to that file, and if so checks group file permissions. If the user is neither the file owner nor in the file's group, they come under the heading of other users. The group to which a file has been allocated must be a valid group the system administrator has already set up, as discussed above. The owner of a file can change the group to which the file has been allocated. Access privileges for directories have a different meaning than
for ordinary files. If a directory has write permission,
files in that directory may be created or deleted. If it has
read permission, it is possible to see the files that are
contained in that directory (using To find out the access privileges for a file, use
total 561 -rw-r--r-- 1 chris ugrads 122 Dec 21 18:40 myfile drwxr-xr-x 2 chris general 512 Dec 22 14:55 dir1 drwx------ 2 chris general 512 Dec 22 14:55 dir2 -rw-r----- 1 chris proj 9912 Nov 22 17:55 prog.c -r-x------ 2 chris general 147 Dec 22 17:56 foo -r-x------ 2 chris general 147 Dec 22 17:56 bar In fact, -rw-r--r-- 1 chris ugrads 122 Dec 21 18:40 myfile ^^^^^^^^^^ ^ ^^^^^ ^^^^^^^^^ ^^^^ ^^^^^^^^^^^^ ^^^^ access links owner group size last change name The access privileges are presented as a string of 10
characters. The first character is usually either a For read privilege, the first character will be
For example, file If a directory does not have write permission, then files in that directory cannot be deleted, nor can new ones be created. However, files within that directory that do have write permission can have their contents changed. The other information that |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck