May 09
A Basic Introduction to chmod for Linux
When I first encountered chmod the numbers (0777 etc) seemed confusing with absolutely no explanation available at the time. It’s actually very straight forward and if you run a Linux distribution at home you will pick it up very quickly.
Understanding Permissions and String Mode
There are various ways you can apply permissions with chmod but two popular methods are via string and octal modes, which we will look at.
String mode example: -rw-rwxr–
Each character refers to a mode like listed below:
- r = read, can read the file/directory
- w = write, can write to the file/directory
- x = execute, can execute (run) the file/directory
In addition to that you also have the hyphen (-) which sets the permission to “None” (applying no permissions). To make more sense of why there are so many modes being set we need to segment the string example.
Ignoring the first mode (which is out of the scope of this reference) we have 9 modes, rw-rwxr–. When you apply permissions you usually do it to three classes;
- User (owner)
- Group (users that are members of the group)
- Others (public)
So the first three characters set the overall mode for the user (rw-), the second set of characters sets permissions for the group (rwx) and the final three is for others (r–). All of those combined create the original string example, rw-rwxr–.
Now that you (hopefully) understand what mode each character represents and what class they are being applied to you should be able to determine that;
- The user (owner) has permission to read and write
- The group has permission to read, write and execute.
- The others (public) have permission to read only.
Understanding Octal Modes
You’ll most likely have encountered octal representations like 0755, 0777 etc. Like in the string mode explanations above ignore the 0 class.
Using octal numbers is easier and shorter but now you understand string modes and the different permission classes it should be much easier to learn.
If we converted the string mode rw-rwxr– to octal it would be represented as 0674. Each individual number is a reference to a mode, or combination of modes. If we segment the number 6 is applied to the user, 7 to the group and 4 to others (public).
So how did we get the numbers in the first place? The list below shows what each number represents.
- 0 = None/Nothing
- 1 = Execute
- 2 = Write
- 4 = Read
That’s the actual list, however we can combine the modes. For example read (4) + write (2) = 6. If we create a full list it now looks like this:
- 0 = None/Nothing
- 1 = Execute
- 2 = Write
- 3 = Executive and Write (2 + 1 = 3)
- 4 = Read
- 5 = Read and Execute (4 + 1 = 5)
- 6 = Read and Write (4 + 2 = 6)
- 7 = Read, Write and Executive (4 + 2 + 1 = 7)
Once you understand what each number or character does and to what class the permissions are being applied to it’s very easy to understand chmod and hopefully this reference has shown that!
Applying Permissions
So how do you actually apply the permissions? To do it remotely most FTP clients come with tools that allow you to set them.

Change Mode with FireFTP
To set permissions locally (on your computer) or remotely (via SSH etc) via command line you use the chmod command, funnily enough!
To view the permission of each file and directory (string mode) within the current working directory use something similar to:
ls -la
Now to actually apply permissions to a file directory the syntax is:
chmod [OPTION]... MODE... FILE
For example:
chmod 0674 test.txtTo apply recursive permissions (to each and every file/directory in the current working directory) you would apply the -R option and a wildcard (*).
chmod -R 0755 *
To recursively apply permissions to a different directory replace * with the full or relative path to that directory.
chmod -R 0755 /home/user/directory
chmod is powerful and there are numerous ways to apply permissions and lots of different options and arguements. To read the chmod manual via the terminal run
man chmod
Hopefully, if you didn’t already know, you now understand those letters/numbers, what they do and what they are being applied too.
Bookmark or share this page:
MSN Contact: contact [at] danielgibbs.net
Dan Gibbs is a web developer, designer and SEO consultant involved in devon web design.





