File Permissions

File permissions are set with the chmod command. The permissions of a file can only be changed by the owner of the file, or by the superuser. There are nine main permissions; read, write and execute which apply to the three groups: owner (user), the departmental or college (group) and everyone else, i.e. the world! (other).

The existing permissions of a file can be seen from a directory listing, for example the following command would display information on the file index.html.

% ls -l index.html
-rw-r--r-- 1 mary xzug 962 Aug 31 11:49 index.html

The first character (of -rw-r--r--) denotes the special attributes of a file, for example d denotes a directory, l denotes a symbolic link. The next three sets of three characters each denote read, write and execute permission for user, group and other respectively. In the above example, the owner mary, has rw- permissions for the file index.html, the group xzug has r-- (read) permission only, as does other.

Note, that permissions for a directory entry are treated in exactly the same way. A directory must at least have execute permission for the user to open it.

All of these permissions can be altered in one go, by specifying the permissions for the user, the group and other as three separate digits. Each digit is calculated from the permissions desired; count read permission as 4, write permission as 2 and execute permission as 1. For example, 5 means r-x permissions, 6 means rw- permission and 7 means rwx permission. So 666 is read and write (rw-) permission for the user, group and other users (ie rw-rw-rw-), whilst 754 is rwx permission for the owner, r-x for the group and r-- for other users (ie rwxr-xr--).

chmod 754 filename sets the permissions of filename to be rwxr-xr--

It is also possible to modify a particular permission independently.

Command, Effect

chmod a-w filename
remove write permission for user, group and other
chmod u+x filename
adds execute permission for the user only
chmod g-r filename
removes read permission for the group only
chmod o+w filename
adds write permission for other users only
chmod a+r,o-w filename
adds read permission for all and removes write permission for other. Note, there is no space between a+r, and o-w.

Help: for more information see chmod(1).

Changing Default File Permissions

The command to change the default permissions for your files and directories is umask. The system default permissions (following the octal numbering discussed in the section above) are initially set to be 666 for files and 777 for directories. The system default value for umask is then subtracted from one of these two values (depending on whether it is a file or directory) to give the settings for any newly created files.

For example, if the system default umask value is set to 026, then a newly created file would have permissions set to (666 - 026), i.e. 640 which is rw-r-----. This gives read and write permission to the user, read permission to the group and no permissions for other. With the same default umask value of 026, if a user creates a new directory this will be given permissions (777 - 026), i.e. 751 which is rwxr-x--x.

Type umask to see the current value set (preceding zeros are generally omitted). Use umask nnn where nnn is an octal number to change the settings. If you wish to override the system default value for umask for each new login session, place the command in the .login file.

Help: for more information see csh(1) and type /umask to search through the pages. There is further explanation in the example .login file at the end of this document.

File Links

A directory entry can be set to point to another file. Links can be set up to point to files in system directories, other user's directories and other file systems. The default is a hard link; the directory entry points to exactly the same place that the original filename points to. A symbolic link can be created using the -s option with the link command ln. Symbolic links are files that point to the original filename (which in turn points to where the actual data is stored). Hard links cannot be made to other file systems or directories. The command takes the form:

ln -s existingname extraname

Here is an example of creating a symbolic link to a directory:

% ln -s /usr/etc/htdocs/OUCS/Courses courses

The above directory is where all the course files are kept. courses is now a symbolic link to the directory /usr/etc/htdocs/OUCS/Courses. courses can be treated as a directory, for example,

% cd courses

would change to the directory /usr/etc/htdocs/OUCS/Courses. Using the command ls -l courses would now display

lrwxrwxrwx 1 mary 2 Jun courses->/usr/etc/htdocs/OUCS/Courses

where the first character, l, denotes the link. To remove the above link use unlink courses.

Help: for more information see ln(1) and unlink(1).