chmod (which stands for "change mode") changes who can access a particular file. A "mode" is created by combining the various options from who, opcode, and permission.
It should be noted that you can also chmod your files using FTP or Cpanel. Here we are discussing Unix Commands, but the values (rxw or 421) used to chmod are the same with all programs.
Structure: chmod [option] mode file
If you look at a list of files using the long list format ls -l, you'll see the permissions, owner, file size, modification time, and filename. The first column of the list shows who can read, write, and execute the files or directories - in other words, the permissions. It basically shows who has permission to do what to a given file or directory.
r stands for "read" and means that you're allowed to read the file or directory.
w stands for "write" and gives permission to edit or change the file as well as create, move, rename, or remove a directory.
x stands for "execute," which gives permission to run a file or search a directory.
Every file or directory has four sets of rwx permissions. The first set represents the user (u), the second set represents the group (g), the third set represents other (o), and the fourth set represents all (a). The column will look like this:
Each set of rwx represents user, group, and other respectively. Only the owner of a file or a privileged user may change the permissions on a file.
There are two ways to change permissions on a file or directory, either numerically or by using lettered commands. Both ways use the command chmod.
To add permissions to a file, you use +, to remove permissions you use-. Take this file for example:
-rw-r--r-- 1 me mygroup 832 May 21 19:42 pagename.html
To allow a group (mygroup, in this case) "write" access, you would type:
chmod g+w pagename.html
If you wanted to remove "read" ability from "other" you would type:
chmod o-r pagename.html
It is also possible to specify permissions using a three-digit sequence. This is a more efficient way to change permissions (or at least it requires less typing), so use this method if it doesn't confuse you. Each type of permission is given an numerical value:
Read is given the value of 4,
write is given the value of 2
execute is given the value of 1
These values are added together for each user category. The permissions are changed by using a *three-digit sequence with the first digit representing owner permission, the second digit representing group permission, and the third digit representing other permission.
For example, if you wanted to make pagename.html readable, writable, and executable for the user, readable and writable for the group, and readable for other, you would type:
chmod 764 pagename.html
The first digit 7 means readable and writable for the user (4+2+1=7), the second digit 6 means readable and writable for the group (4+2=6), and the third digit 4 means readable for other (4).
If you want to change the permissions on a directory tree use the
chmod -R will recursively change the permissions of directories and their contents.
Common CHMOD values and what they mean.
chmod 777 filename Read, Write, and Execute for the user, group, and world.
chmod 755 filename Read, Write, and Execute for the user; and Read and Execute only for the group and world.
chmod 644 filename Read and Write for the user, and Read only for the group and world.
chmod 666 filename Read and Write for the user, group, and world.
To see what different chmod values look like, click on the boxes and watch as the numbers change.
Now you are confused because we told you at the top of the page that there are four groups of permissions, and now you see permissions being referenced as a three digit sequence. I am glad you caught that. It means you were paying attention.
For a .cgi (or perl) file to work, it must be owned by 'somebody' who is called 'Nobody'. You may see a script that says to chmod a file at 0777. The first number is for Nobody, and is usally zero. The next three are for the User, (webmaster) Group, and World. Only the web server host can set permissions for nobody, so even with a zero or without, Nobody still retains ownership.
In fact that is why you will usually only see the three settings for chmod.
Back to Unix Commands
- Account Log ins
Control Panel Sample
- Getting Started
Chosing a Password
Anti Spam Tips
- Creating Databases
- Unix Commands
Telnet / SSH