FTP Wysardry
Using FTP Clients

UNIX file and directory permissions a.k.a. CHMOD



Home / FTP / UNIX Permissions

Back | Next

Overview

This information is already in the Perl Script tutorial section, but as it is one of the most common problems that people have to face when first learning how to write and/or configure their first scripts I am also including it here.

It is also relevant to those using PHP programs which write to files.

Please note that we will be using the term 'UNIX' in a generic sense, and that these concepts also apply to the many variations such as Linux and BSD.


User Types

Because UNIX is a multi-user environment it has to keep track of ownership and operation privileges for different users.

There are three basic types of user when dealing with CGI scripts- User, Group and Other.

  • User - the owner of the file (whoever logged in and uploaded it).
  • Group - users who are part of the owner's group (not really used on Web servers).
  • Other - everyone else (also known as the world).

These can be abbreviated to U, G and O.

Please note:

Scripts seem to run as 'Other' on Spaceports.  Bear that in mind when setting permissions of associated log files.


File permissions

Every file has permissions associated with it which control what can be done with that file and by whom.  There are three possible operations that can be carried out on a file:-

  • Read - read the file.
  • Write - modify or delete the file.
  • eXecute - execute (or run) the file.

The Owner (and only the Owner) can adjust the permissions for each of these operations for each type of user via FTP or telnet.  Spaceports doesn't currently support CHMOD via telnet however.

These properties can be abbreviated to R, W and X.


Directory Permissions

Permissions used with directories work in a slightly different way:-

  • Read - view the directory contents.
  • Write - create or delete files.
  • eXecute - access the directory.

Be aware that it is possible for somebody with Write permission to delete a file inside that directory even if they don't actually have Write access for that particular file!


Permission Values

Each of these permissions has a value associated with it:-

  • Read = 4
  • Write = 2
  • eXecute = 1

When assigning these permissions you add together the values for the ones you wish to allow.  Use 0 if you do not wish to enable any of the three.


Putting it together

When you set the permission for a file or directory you will need to specify the values for User, Group and Other in that order.  These values correspond to Read, Write and eXecute as explained above.

Scripts are usually set via the CHMOD (CHange MODe) command to 755:-

  • U: RWX= 4 + 2 + 1 = 7
  • G: R-X= 4 + 0 + 1 = 5
  • O: R-X= 4 + 0 + 1 = 5

CHMOD 755 script.cgi

Which basically means the User can read, run and modify the file, but everyone else can only read or run it.


Examples

I will leave you with a few examples of the most commonly used settings:-

  • 755 - (drwxr-xr-x) - Directories containing CGI files
  • 777 - (drwxrwxrwx) - Directories not containing CGI files
  • 755 - (-rwxr-xr-x) - CGI files
  • 666 - (-rw-rw-rw-) - Log files
  • 777 - (-rwxrwxrwx) - HTML files
Site Menu

Bravenet

Section Menu


Copyright © 2000-2003 Wysardry

Most recently updated on 11 May, 2003

Home / FTP / UNIX Permissions

Back | Next


Please feel free to contact us with any comments or suggestions
Using FTP Clients
FTP Wysardry

This site is hosted by Spaceports