Chmod 644,755,777 – what’s the difference

chmod is a program responsible for modifying access permissions of file and directories in Unix/Linux. While the concept is easy to understand, the syntax might overwhelm new users a little bit. Most of the time, you will encounter chmod 777, chmod 755 and chmod 644.

In this article, we will explain the meaning of these numbers and how they are related to the actual permissions. We will also provide quick references on chmod 777, chmod 755 and chmod 644. Before continuing to the next section, you may be interested in our take on explaining chmod +x.

Chmod numbers meaning

Basically, an user group can hold three kind of permissions on a file or directory. One can either read (r), write (w) or execute (x) the file. But these permissions has to be set for each groups of users : Owner, Group, Other.

Every time you need to chmod a file or directory, you need to specify permissions for each groups. Allowing all permissions for all groups would be rwx-rwx-rwx. While the syntax is simple to understand, it is pretty long to type in.

To make chmod commands shorter, people replaced letters with numbers. The original rules involved converting permissions to binary numbers.

But in reality, there's only one rule of thumb you need to keep in mind : read permission equals 4, write permission equals 2, execute permission equals 1.

To convert the letters to the numbers, you need to add up the corresponding numbers for each group and append them together. Let's look at the example below :

Chmod syntax

Owner can read (number 4) and write (number 2), so we have number 4+2=6 for users in the Owner group.

Group (everyone inside the current user's group) and Other can read, so it's number 4.

That's how we got the number 644. Simply put, 6 means "read/write is fine" and 4 means "only read allowed".

Please also do note that the letters and the numbers are equivalent. You can use one of the two format and expect the same result.

Chmod 775 vs chmod 755

chmod 775 means giving the group which the current user belongs to the permission to write. That means anyone can modify or overwrite files even the ones they didn't create, as long as the owner is one of the group members.

chmod 755 means only the owner of the file are allowed to modify or overwrite it.

Generally, 755 is more secure than 775 and should be used by default unless it raises errors.

Chmod 664 vs chmod 644

chmod 664 is equivalent to only owner and his group members can write, others are only allowed to read.

chmod 644 means only the owner are allowed to write/modify, read-only for others (group) included.

There is no number 7 or 5 in the chmod number, which means no one are allowed to execute the file.

Chmod 777 vs chmod 755

A 777 permission on the directory means that anyone can read/write/execute (execute on a directory means that you can run ls to see the contents of it). That is dangerous as anyone who can gain access to the machine can modify or execute your files, which might lead to sensitive information leak.

755 means giving read and execute access for everyone, plus write access for the owner of the file or directory.

For security reasons, no one should chmod 777 on a file except for debugging. Even when you chmod 777 an image file, someone can simply replace the contents of the file with malicious code and run it to gain administrator privileges.

We hope that at the end of this tutorial, you understand the concept behind chmod numbers and the difference between chmod 777, chmod 755 and chmod 644.

Click to rate this post!
[Total: 0 Average: 0]

Leave a Comment