UNIX Tutorial Three

3.1 File system security (access rights)

In your home directory, type

% ls -l (l for long listing)

You will see that you now get lots of details about the contents of your directory, similar to the two entries below.

drwxrw-r-- 5 j f 50 Jan 31 2005 Desktop  
-rwxrw-r-- 5 j f 10 Jan 31 2005 stuff   

Each file (and directory) has associated access rights.  In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -, (and, occasionally, s or S). If d is present, it will be at the left hand end of the string, and indicates a directory: otherwise - will indicate an ordinary file.

The 9 remaining symbols indicate the permissions, or access rights, and are taken as three groups of 3.

The symbols r, w, etc., have slightly different meanings depending on whether they refer to a simple file or to a directory.

Access rights on files.


Access rights on directories.

So, in order to read a file, you must have execute permission on the directory containing that file, and hence on any directory containing that directory as a subdirectory, and so on, up the tree.


Some examples

-rwxrwxrwx

a file that everyone can read, write and execute (and delete).

-rw-------

a file that only the owner can read and write - no-one else 

can read or write and no-one has execution rights (e.g. your 

mailbox file).  

3.2 Changing access rights

chmod (changing a file mode)

Only the owner of a file can use chmod to change the permissions of a file. The options of chmod are as follows

Symbol

Meaning

u

user

g

group

o

other

a

all

r

read

w

write (and delete)

x

execute (and access directory)

+

add permission

-

take away permission

For example, to remove read write and execute permissions on the file mylist for the group and others, type

% chmod go-rwx mylist

This will leave the other permissions unaffected.

To give read and write permissions on the file ourlist to all,

% chmod a+rw ourlist

Exercise 3a

Try changing access permissions on a file  in some directory (you can create a file simply by using the command  touch file ).

Use ls -l to check that the permissions have changed.

Summary

ls -l

list access rights for files

chmod [options] file

change access rights for named file

touch file

create an empty file

















This tutorial was modified by Jay Alan Jackson from the original work by M.Stonebank@surrey.ac.uk, 19 October 2001 in accordance with the Creative Commons License, under which it is still protected.

Creative Commons License