permissions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
permissions [2021/03/09 19:48] – [An example] hc9 | permissions [2024/09/06 06:17] (current) – no” hc9 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Permissions ====== | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | Unix was created to be a multi-user operating system. The intention was not for everybody to have full access to all files, but to allow file owners to specify which users should have what kind of access. | ||
+ | |||
+ | ===== Permissions ===== | ||
+ | |||
+ | A Unix file system allows users to assign to files (including directories: | ||
+ | |||
+ | ==== Permission types ==== | ||
+ | |||
+ | The effect of the three permission types varies depending on whether they apply to a file or a directory. | ||
+ | |||
+ | ^ Type ^ On file ^ On directory ^ | ||
+ | ^ r | Read file contents. | List name, size, modification date, etc. of files in directory.< | ||
+ | ^ w | Change (**w**rite) file contents. | Add or remove files from directory.< | ||
+ | ^ x | Shell will attempt to e**x**ecute file if file name entered by itself on command line. | Access (read or write) the directory< | ||
+ | | **Notes:** < | ||
+ | |||
+ | Unlike some other file systems, such as NTFS, neither **r** nor **w** directory permission have any influence on **r** or **w** permission for subdirectories or files anywhere in the directory' | ||
+ | |||
+ | However, directory **x** permission //does// affect permissions for subdirectories and files farther down the directory subtree. To access a file, a user must have **x** permission on every directory in the file's path. In other words, lack of **x** permission for a directory effectively prevents access to any files in the directory' | ||
+ | |||
+ | ==== User classes ==== | ||
+ | |||
+ | For a given file, the Unix file system divides users into three classes: | ||
+ | |||
+ | ^ Class ^ Users ^ | ||
+ | ^ u | // | ||
+ | ^ g | // | ||
+ | ^ o | // | ||
+ | | **Notes:** < | ||
+ | |||
+ | ==== An example ==== | ||
+ | |||
+ | File permission information can be obtained with the long listing option of the '' | ||
+ | |||
+ | | '' | ||
+ | | '' | ||
+ | | '' | ||
+ | | //a// | | //b// | //c// | | | | | ||
+ | |||
+ | Field //a// is the //file mode//, a string of ten one-character flags that indicate the file's permissions and other information. The following is a list of mode flags in character order with a partial list of possible flag values for each: | ||
+ | |||
+ | |1|File type.| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |2|**r** permission for file owner (user class **u**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |3|**w** permission for file owner (user class **u**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |4|**x** permission for file owner (user class **u**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |5|**r** permission for file user group (user class **g**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |6|**w** permission for file user group (user class **g**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |7|**x** permission for file user group (user class **g**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |8|**r** permission for other users (user class **o**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |9|**w** permission for other users (user class **o**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |10|**x** permission for other users (user class **o**).| | ||
+ | | |'' | ||
+ | | | '' | ||
+ | |||
+ | Field //b// is the user ID of the //file owner//. Field //c// is //user group// the file has been assigned to. | ||
+ | |||
+ | So for the three files in the '' | ||
+ | |||
+ | Directory '' | ||
+ | |||
+ | User '' | ||
+ | User '' | ||
+ | User '' | ||
+ | |||
+ | ==== Links and permissions ==== | ||
+ | |||
+ | In general, the above discussion also applies to hard and symbolic file links. The files system automatically maintains links to keep the same effective permissions as the target file. (For symbolic links, the '' | ||
+ | |||
+ | However, it is possible for hard links to avoid directory **x** permission restrictions in some configurations. Suppose a user has access to a file '' | ||
+ | |||
+ | ===== Changing permissions… ===== | ||
+ | |||
+ | Permissions are changed with the command '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | Let's take a look at this example, | ||
+ | |||
+ | '' | ||
+ | |||
+ | What does that number, 644, stand for? | ||
+ | |||
+ | ===== …explained ===== | ||
+ | |||
+ | The // | ||
+ | |||
+ | ^ User class: ^ u ^ g ^ o ^ | ||
+ | ^ Permission code: | 6 | 4 | 4 | | ||
+ | |||
+ | The permission code for each use class is calculated by summing the values corresponding to the permission types assigned to the user class: 4 for **r** permission , 2 for **w** permission, 1 for **x** permission. | ||
+ | |||
+ | In the above example, I want file '' | ||
+ | |||
+ | ^ User class ^ Permission types ^ Permission code ^ | ||
+ | ^ u (myself) | **r** (4), **w** (2) | 4 + 2 = **6** | | ||
+ | ^ g (group) | **r** (4) | **4** | | ||
+ | ^ o (others) | **r** (4) | **4** | | ||
+ | |||
+ | Thus: | ||
+ | |||
+ | '' | ||
+ | |||
+ | Et voila! | ||
+ | |||
+ | ===== …another way ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |1|// | ||
+ | | |User class(es) for which permissions are to be changed. Specify with one-character class symbols '' | ||
+ | |2|// | ||
+ | | |One of the following:| | ||
+ | | | '' | ||
+ | | | '' | ||
+ | | | '' | ||
+ | |3|// | ||
+ | | |Permission type(s) to be set or removed. Use one-character type symbols '' | ||
+ | |||
+ | Therefore the command: | ||
+ | |||
+ | '' | ||
+ | |||
+ | would have the same effect as the example command: | ||
+ | |||
+ | '' | ||
+ | |||
+ | If I later wanted to give **w** permission to members of the file's user group, I could use the command: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== File Flags ===== | ||
+ | |||
+ | In addition to the file permissions we've already discussed, we also have file flags. File flags add additional security and control over files, but not directories. File flags are altered using the chflags(1) utility. | ||
+ | |||
+ | '' | ||
+ | |||
+ | would be used to set the user undelete flag, and to disable that flag, simply add “no” in front of the option (in this example, uunlnk), like so: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ---- | ||
+ | |||
+ | $Id: permissions.html, | ||