Access Classes File ProtectionFile Access

ls homeusername none r ls −s homeusername none rx A file size determination requires a logical move to the directory itself to search the content of the inode of the specified file cat filename r x cat filename w x filename x if binary x filename rx if script x rm filename w xw w permission for a file is not a requirement but an additional confirmation will be required; w permission for a directory is mandatory removing a file means altering the directory Notes: It is important to understand the difference between a simple ls command, and any other, more elaborated ls command with an option that requires a search of the files inode. Simple listing of the directory means just to read the content of the directory; options require information from the inode of the specified file.

2.2.2.1 Access Classes

UNIX defines three basic classes of access to files, for which permissions can be specified separately: User access u Access granted to the user−owner of the file Group access g Access granted to members of the group that owns the file Other access o Access granted to everyone else except root All classes a Access granted to everyone includes all three classes The access classes independently specify file modes for different categories classes of users. The long format the − l option of the ls command is used to display the file mode — see the previous example. The first column in the listing, a set of letters and hyphens, represents a file mode; the file mode includes three triplets for the three access classes u, g, and o. This is illustrated in the following table: File Type User Access u Group Access g Other Access o Position 1 2 3 4 5 6 7 8 9 10 Letter − r w x r w x r w x Read access + + + Write access + + + Execute access + + + Note:The first letter or hyphen in a line the leftmost position represents a file type. 35 We have already discussed myriad terms to refer to file protection; UNIX simply refers to a file protection as file mode. In UNIX parlance, to set file permissions means to change a file mode; for that purpose, the UNIX chmod command is used: chmod access−string filenames where access−string Includes: Access class: u, g, o, or a • Operator: +, −, or = • Permissions: r, w, or x • filename File name in the current directory, or the full−path file name multiple files are separated by a space. Multiple access classes andor permissions could be also simultaneously specified. The recursive chmod command is also supported, for example: chmod −R go−rwx homeusername This command will change the file mode of all files and subdirectories beneath the directory homeusername. It will deny any kind of access for group and other, and the user access will remain unchanged. This example specifies the file mode, using what is called symbolic mode notation. Alternatively, the absolute, or numeric, mode notation could be also used. The difference between the two is shown below: user group other Access classes r w x r – x r−− Symbolic mode 1 1 1 1 0 1 1 0 0 Convert to binary 7 5 4 Convert to digit 754 The corresponding absolute numeric mode The command to set this particular file mode is: chmod 754 filename Access rights for a certain user are strictly determined by the individual permissions within the related class. It means that UNIX first determines where the user belongs – is that the user−owner, a member of the group−owner, or any other user. Once it is done, only the related files access class is checked and accordingly a needed access to the file granted or denied. There is no a gradual top−down access class checkup in the cases when an user belongs to multiple classes an user−owner could also be a member of the group−owner, and definitely belongs to others. Here is an example: The user is bjl; the long listing for the text file textfile is: ls −l testfile −rw−r−−r−− 1 bjl users 15 Jul 6 20:49 textfile 36 cat textfile This is just a test file Let us deny read access to the user−owner bjl: chmod u−r testfile ls −l testfile −−w−r−−r −− 1 bjl users 15 Jul 6 20:49 textfile • And try to read the file again: cat textfile cat: textfile: Permission denied • However, the file can be modified echo This is added text textfile echo textfile • Besides the fact that user bjl is the owner of the file textfile and a member of the group users, as well as that read permission is granted to the group users and to all others, the file cannot be opened for reading. The files owner, user bjl, can modify or delete the file there is the w permission, but the file cannot be read. To overcome this unusual situation, the owner has to change the file mode, and make the file readable. chmod 644 testfile ls –l testfile −rw−r−−r−− 1 bjl users 15 Jul 6 20:49 textfile cat textfile This is just a test file This is added text • The same is valid for a group−owner toward group permissions. •

2.2.2.3 Default File Mode