Definition

chmod is a Unix command for setting the permissions of a file. It is short for change mode.

If you are using a Unix or Linux server to host your website you will probably need to understand the chmod command. This command is used to tell the server who can do what with the files located there.

Permissions

WHO

There are three "whos" that a Unix server is concerned with:

  • The individual owner of the file
  • The group that owns the file
  • Every other user

Each file has an owner. If you are paying someone to host your web site it is very likely that they have set things up so that YOU are the owner of all of the files in the directories that make up you web site.

Each user in the system can belong to one or more groups. The group permissions effect anyone who belongs to the group that owns the file.

If you aren't the owner and don't belong to the group that owns the file you are just a user. Someone browsing your web site falls into this category.

↑ Contents

WHAT

There are three things you can do with a file:

  • Read it
  • Write it
  • Execute it

Reading a file means you can look at it. In the case of a visitor to your website, it usually means that they can see it in their browser.

Having write permissions on a file means that you can edit it, make changes to it, even erase it.

Execute permissions mean that the file can be run on the server. The file is executed by the server. When using a script written in PERL (like Coranto) the script file must have execute permissions or the server will not run them.

Here is the properties window for a file on this server. The window is from the FTP program Smart FTP. In Smart FTP you use this form to set file permissions. Other ftp clients use different methods, read the docs for your ftp program for details.

↑ Contents

Attach:chmod_example.png Δ

This shows the typical chmod value of 755 for scripts. You can see the three types of users that permissions can be set for and the three types of permissions you can set. You may also see the permissions of a file expressed like this:

-rwxr-xr-x

This representation of the files permissions means exactly the same thing as 755. Her is how we get to that:

The first column is the filetype if this were a directory it would be d

The next three columns (rwx in our example above) are the owners permissions. In this case the owner can read, write, and execute the file.

The next three columns are the group's permissions (r-x in our example above). The group members can read and execute the file. The dash in the middle position means that the group does not have write permissions.

The next three columns are the permissions for all other users(r-x in our example above). Everyone else can read and execute the file, but they do not have write permissions.

The way that this translates into the 755 is that each type of permission has a value.

  • read = 4
  • write = 2
  • execute = 1

Adding up the permissions allowed for each type of user gives you the three digit equivalent of the files permissions

↑ Contents

Click on the link below to view a demo that shows the relationship between the three digit numbers and permissions shown in a listing on the server (uses javascript).

chmod Demo

For a more detailed tutorial to chmod see Dave Eisenberg's chmod Tutorial

Revision History

  • January 16, 2009 - Copyright updated, links corrected.
  • July 28, 2006
    • Reformatted and published to this wiki
  • Originally published December 9, 2003

↑ Contents

Copyright

Original contributed by Dale Ray, written December 9, 2003.

Copyright/License

No warranty, promises. or guarantees

The information in this document is accurate to the best of my knowledge. Use this information at your own risk. Make back ups and back ups of your back ups. There are no promises or guarantees of the fitness of this information for any use. There are no implied or stated warranties.

↑ Contents

Category:




Page last modified on February 03, 2009, at 01:10 AM