"Every user on a Unix system has a unique username, and is a member of at least one group (the primary group for that user). This group information is held in the password file (/etc/passwd). A user can also be a member of one or more other groups. The auxiliary group information is held in the file /etc/group. Only the administrator can create new groups or add/delete group members (one of the shortcomings of the system).
Every directory and file on the system has an owner, and also an associated group. It also has a set of permission flags which specify separate read, write and execute permissions for the 'user' (owner), 'group', and 'other' (everyone else with an account on the computer) The 'ls' command shows the permissions and group associated with files when used with the -l option. On some systems (e.g. Coos), the '-g' option is also needed to see the group information.
An example of the output produced by 'ls -l' is shown below.
drwx------ 2 richard staff 2048 Jan 2 1997 private
drwxrws--- 2 richard staff 2048 Jan 2 1997 admin
-rw-rw---- 2 richard staff 12040 Aug 20 1996 admin/userinfo
drwxr-xr-x 3 richard user 2048 May 13 09:27 public
Understanding how to read this output is useful to all unix users, but especially people using group access permissions.
Field 1: a set of ten permission flags.
Field 2: link count (don't worry about this)
Field 3: owner of the file
Field 4: associated group for the file
Field 5: size in bytes
Field 6-8: date of last modification (format varies, but always 3 fields)
Field 9: name of file (possibly with path, depending on how ls was called)
The permission flags are read as follows (left to right)
| position | Meaning |
|---|---|
| 1 | directory flag, 'd' if a directory, '-' if a normal file, something else occasionally may appear here for special devices. |
| 2,3,4 | read, write, execute permission for User (Owner) of file |
| 5,6,7 | read, write, execute permission for Group |
| 8,9,10 | read, write, execute permission for Other |
| value | Meaning |
| - | in any position means that flag is not set |
| r | file is readable by owner, group or other |
| w | file is writeable. On a directory, write access means you can add or delete files |
| x | file is executable (only for programs and shell scripts - not useful for data files). Execute permission on a directory means you can list the files in that directory |
| s | in the place where 'x' would normally go is called the set-UID or set-groupID flag. |
On an executable program with set-UID or set-groupID, that program runs with the effective permissions of its owner or group.
| For a directory, the set-groupID flag means that all files created inside that directory will inherit the group of the directory. Without this flag, a file takes on the primary group of the user creating the file. This property is important to people trying to maintain a directory as group accessible. The subdirectories also inherit the set-groupID property. |
It is used in UNIX long directory listings. It consists of 10 characters. The first character shows the file type. Next 9 characters are permissions, consisting of three groups: owner, group, others. Each group consists of three symbols: rwx (in this order), if some permission is denied, then a dash "-" is used instead. Example:
-rwxr--r--
0123456789
- Symbol in the position 0 ("-")is the type of the file. It is either "d" if the item is a directory, or "l" if it is a link, or "-" if the item is a regular file.
- Symbols in positions 1 to 3 ("rwx") are permissions for the owner of the file.
- Symbols in positions 4 to 6 ("r--") are permissions for the group.
- Symbols in positions 7 to 9 ("r--") are permissions for others.
| r | Read access is allowed |
| w | Write access is allowed |
| x | Execute access is allowed |
| - | Replaces "r", "w" or "x" if according access type is denied |
2.1.1. Examples
| -rwxr-xr-x | File, owner has read, write, execute permissions, group: only read and execute permissions, others: only read and execute permissions. |
| dr-x------ | Directory, owner has read and execute access, group and others have no access |
Numeric (octal) representation like "644"
If a numeric representation is used (like in chmod command, for example), then it is in the octal format (with the base of 8), and digits involved are 0 to 7. Octal format is used for the simplicity of understanding: every octal digit combines read, write and execute permissions together. Respective access rights for owner, group and others (in this order) are the last three digits of the numeric file permissions representation. Example: "0644". Here the second digit ("6" in the example) stands for rights of the owner, the third digit ("4" in the example) stands for rights of the group, the fourth digit ("4" in the example) stands for rights of others.
This table shows what numeric values mean:
| Octal digit | Text equivalent | Binary value | Meaning |
|---|---|---|---|
| 0 | --- | 000 | All types of access are denied |
| 1 | --x | 001 | Execute access is allowed only |
| 2 | -w- | 010 | Write access is allowed only |
| 3 | -wx | 011 | Write and execute access are allowed |
| 4 | r-- | 100 | Read access is allowed only |
| 5 | r-x | 101 | Read and execute access are allowed |
| 6 | rw- | 110 | Read and write access are allowed |
| 7 | rwx | 111 | Everything is allowed |
We see that "1" stands for execute only, "2" stands for write only, "4" stands for read only. To combine the permissions you can simply add 1, 2 and 4 to get a needed combination. For instance, to get read and write permissions, you add 4 (read) and 2 (write), thus getting 6 (read and write). To get read and execute permissions, you add 4 (read) and 1 (execute), thus getting 5 (read and execute).
Examples
| 644 | owner: read and write permissions, group: only read permissions, others: only read permissions. |
| 755 | owner: read, write and execute permissions, group: read and execute permissions, others: read and execute permissions. |
Why there is a leading zero?
In programming, for instance, in C language, leading zero means that the value is in the octal format. Basically, it can be omitted. Owner, group and others rights are the last three digits of the permissions.
Four meaningful digits like "4755"
There are cases when you may come across four non-zero digits, in this case the first meaningful (non-zero) digit combines the following bits (in this order, high to low): SUID, SGID, sticky bit. We also know that the last three are for owner, group and others.
See this table for more information about SUID and so on.
Difference in access permissions for files and folders
Access permissions for files and folders mean different things from the user standpoint. The table below shows the difference.
| Access type | File | Folder |
|---|---|---|
| Read | If the file contents can be read | If the directory listing can be obtained |
| Write | If user or process can write to the file (change its contents) | If user or process can change directory contents somehow: create new or delete existing files in the directory or rename files. |
| Execute | If the file can be executed | If user or process can access the directory, that is, go to it (make it to be the current working directory) |
The default file permissions (umask):
Each user has a default set of permissions which apply to all files created by that user, unless the software explicitly sets something else. This is often called the 'umask', after the command used to change it. It is either inherited from the login process, or set in the .cshrc or .login file which configures an individual account, or it can be run manually.Typically the default configuration is equivalent to typing 'umask 22' which produces permissions of:
-rw-r--r-- for regular files, orIn other words, user has full access, everyone else (group and other) has read access to files, lookup access to directories.
drwxr-xr-x for directories.
When working with group-access files and directories, it is common to use 'umask 2' which produces permissions of:
-rw-rw-r-- for regular files, orFor private work, use 'umask 77' which produces permissions:
drwxrwxr-x for directories.
-rw------- for regular files, orThe logic behind the number given to umask is not intuitive.
drwx------ for directories.
The command to change the permission flags is "chmod". Only the owner of a file can change its permissions.
The command to change the group of a file is "chgrp". Only the owner of a file can change its group, and can only change it to a group of which he is a member.
See the online manual pages for details of these commands on any particular system (e.g. "man chmod").
Examples of typical useage are given below:
-
chmod g+w myfile - give group write permission to "myfile", leaving all other permission flags alone
-
chmod g-rw myfile - remove read and write access to "myfile", leaving all other permission flags alone
-
chmod g+rwxs mydir - give full group read/write access to directory "mydir", also setting the set-groupID flag so that directories created inside it inherit the group
-
chmod u=rw,go= privatefile - explicitly give user read/write access, and revoke all group and other access, to file 'privatefile'
-
chmod -R g+rw . - give group read write access to this directory, and everything inside of it (-R = recursive)
-
chgrp -R medi . - change the ownership of this directory to group 'medi' and everything inside of it (-R = recursive). The person issuing this command must own all the files or it will fail.
WARNINGS:
Putting 'umask 2' into a startup file (.login or .cshrc) will make these settings apply to everything you do unless manually changed. This can lead to giving group access to files such as saved email in your home directory, which is generally not desireable.
Making a file group read/write without checking what its group is can lead to accidentally giving access to almost everyone on the system. Normally all users are members of some default group such as "users", as well as being members of specific project-oriented groups. Don't give group access to "users" when you intended some other group.
Remember that to read a file, you need execute access to the directory it is in AND read access to the file itself. To write a file, your need execute access to the directory AND write access to the file. To create new files or delete files, you need write access to the directory. You also need execute access to all parent directories back to the root. Group access will break if a parent directory is made completely private.
AFS Access Control Lists (ACLs)
Files on the central AFS fileservers all have the traditional Unix permissions as explained above, but they are also controlled by Access Control Lists (ACL) which take precedence. They provide access levels more flexible than the user/group/other attribute bits, but they work on the level of complete directories, not files. The command to set and list ACLs is fs."fs" is a big ugly command that does lots of things related to AFS filesystems depending on the arguments you call it with.
For details see the man pages for: fs_setacl, fs_listacl, fs_cleanacl, fs_copyacl
For brief help, do (e.g.) "fs help setacl"
The default is to give the same permissions to a new directory as are on the parent directory. In practice, this is usually to give complete rights to the owner of the directory, and lookup rights to any other user (equivalent to execute attribute on a directory).
To render a directory private, the simplest command is:
fs setacl -d DIRNAME -clear -a MYNAME all
- replace DIRNAME with the appropriate directory name (or "." for the current directory, and MYNAME with your login name.
Check it with:
fs listacl DIRNAME
It should reply with:
Access list for DIRNAME is
Normal rights:
USERNAME rlidwka
(see man fs_setacl for a description of the meaning of the flags "rlidwka")
To explicitly give public read/lookup access, use:
fs setacl -d DIRNAME -a system:anyuser read
This can be abbreviated to
fs sa DIRNAME system:anyuser read
If "fs" is not found, or the man pages are not found, your paths are not set up correctly. I recommend you run /usr/local/bin/mknewdotfiles to correct that.
No comments:
Post a Comment