What Is CHMOD?

May 2nd, 2006 by admin

So you have a script to install on your server and your reading the directions and it mentions that certain file or directory permissions must be CHMOD 755 or 777 or 666, etc.. What is CHMOD? CHMOD is short for Change Mode. It is a Unix command that sets the access limits on a file or directory.

For any operating system based on Unix (i.e. Linux), permissions are very important. There are many files you don’t want other files to touch. It wouldn’t be a good situation is for example, your forum PHP script started overwriting, or reading your servers password files, or deleted directories all over the place.

When using Perl, generally most operating systems will require you CHMOD a Perl script executable before it can be run. This is a security plus compared to PHP where generally, if the PHP file exists, it is automatically executable. So if you have a PHP script that can write to your server, and that script creates another PHP script, it could run arbitrary commands on your server. This is of course, not a good idea.

So what do the numbers mean when you see “CHMOD 755″. This is a bit technical, as the numbers are just a binary representation of a permission scheme.

The CHMOD command takes three arguments, for example:

“CHMOD rwx r-x r-x somefile.cgi” tells the server that the owner of the file can read it, write to it, and execute it. If this was a directory, substitute search for execute.

Breaking it down:

rwx <- file owner
r-x <- user group
r-x <- everyone else

How does this convert to numbers? Basically the "-" symbol equals 0, and everything else equals 1. So the first part of our CHMOD command: rwx equals 111, the second and third part, r-x equals 101. In binary, this comes to 755. Here is a simple binary chart:

000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7

So instead of writing “CHMOD rwx r-x r-x somedirectory” you can write “CHMOD 755 somedirectory”. Many FTP programs such as WS_FTP allow you to use check boxes to set permissions.

You should take care in setting files CHMOD 777. This basically means anyone can read/write/execute/search the file/directory.

Permission structures can be a bit tricky from server to server depending on file ownership. Usually only the file owner can change permissions. Most FTP programs will let you view the entire directory listing which should show you who owns the file, and what group has access to the file as an owner.

This entry was posted on Tuesday, May 2nd, 2006 at 8:04 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply