Permissions


Permissions tell UNIX what can be done with a file and by whom.

There are three types of permissions:

  1. r - read the file or directory
  2. w - write to the file or directory
  3. x - execute the file or search the directory

These permissions allow...

  • Read - read a file, or list files in the directory.
  • Write - read, write, create, rename, delete or list files in the directory.
  • Execute - read, write, create, rename, delete, execute a file or a shell script, or list files in a directory

Each of these permissions can be set for any one of three types of user:

  1. Owner - the person who owns the file
  2. Group - The members of the group to which the owner belongs
  3. World - Everybody else

Permissions can be changed using the chmod command. The syntax for using the chmod command involves using numbers to represent the different permission values.

Read permission is given the value 4
write permission the value 2
and execute permission 1.

r w x
4 2 1

These values are used to represent the permission for each category of user:

1 execute only
2 write only
3 write and execute (1+2)
4 read only
5 read and execute (4+1)
6 read and write (4+2)
7 read and write and execute (4+2+1)

Access permissions are set using three digit representation.

For example:

  Owner Group World
chmod 664 rw- rw- r--
chmod 755 rwx r-x r-x
chmod 764 rwx rw- r--

Permissions for files should be set to:

  Owner Group World
chmod 664 rw- rw- r--

Permissions for folders should be set to:

  Owner Group World
chmod 775 rwx rwx r-x