Chmod 777 Command in Linux (Explained)
In this article, we have detailed what chmod 777 means in Linux and whether you should use it or not. But before that, we have explained the file permission model in Linux. So let’s get started.
How Does File Permission Work in Linux?
Before we understand the chmod 777 command, let’s first get a basic idea of how the file permission model works in Linux. Access to files and directories in Linux is not available to everyone. They are divided on the basis of ownership and attributes. There are three distinct classes of users who can access the filesystem, and they are as follows:
OwnerGroupOthers
Here, “Owner” pertains to the file owner who created the file/ directory. “Group” refers to a set of members, and “Others” are everyone else with access to the system. Each of these classes has a different set of permission attributes. There are again three types of permission: read (r), write (w) and execute (x).
Read (r) – The user can only read or view the file/ directory. They cannot make any changes to the file.Write (w) – The user can modify the file or directory. You can delete, move, rename, or make any changes to the file or directory.Execute (x) – The user can run the script or make a file executable.
To give you an example, a file owner will likely have all three permissions (rwx), whereas a group member or other users in the system may only have read (r) permission. If you have downloaded a script or an executable from the internet, the system owner will have read and write permissions, but not the execute permission granted by default. Basically, all three classes of users will have different combinations of permissions for a file or directory. Now that you have a basic understanding of the permissions model, it’s time to learn about the numbering system for permissions in Linux.
File Permissions in Linux: Numeric Value System
In Linux systems, read, write and execute permissions are denoted in the following fashion. The numeric values for these permissions are derived from their binary 8-bit data, but we are not going into too many details to keep the guide easy to understand.
Read (r) – 4Write (w) – 2Execute (x) – 1No permission – 0
There can be a number of combinations for different sets of permissions based on the above number system. Most of these use a three-digit system, representing a sum of the permission numbers. Refer to the below table to understand this in a better way. ValuePermissionNotation0 (0+0+0)No Permission—1 (0+0+1)Only execute–x2 (0+2+0)Only write-w-3 (0+2+1)Write and execute-wx4 (4+0+0)Only readr–5 (4+0+1)Read and executer-x6 (4+2+0)Read and writerw-7 (4+2+1)Read, write, and executerwx As you can understand from the above table, the 7 value denotes rwx permission combination. So if a file or directory has been granted permission with the 7 value, it has all three privileges – read, write and execute. But what does three 777 mean in Chmod command? Well, move to the next section to understand what Chmod 777 means in Linux.
What Does Chmod 777 Permission Mean?
One final thing that you need to know before moving forward is that these numbers denote the complete set of file/ directory permissions. Here, the first digit refers to the Owner, the second digit refers to the Group, and the third one to Others. We have explained this with the example of the chmod 777 command below.
Chmod essentially means “change the mode” of the file or directory. And when I say 777, the first digit (7 in this case) refers to the owner’s permission. The second digit (again, 7) refers to the Group’s permission, and the third digit (also, 7) indicates the permission value for other users. To sum it up, 777 means the file/ directory is granted read, write and execute permissions for all three user classes, including the owner, group members, and others. It’s denoted as rwxrwxrwx.
Basically, anyone in the system can view, modify, delete, execute or do anything with the file or directory once this command is used. That’s why the chmod 777 command is considered very sensitive, and users are strongly discouraged from using it. This may pose a security risk and leave your web server exposed to malicious actors.
As an alternative, we recommend using the better and safer chmod 644 command to set file permissions. As you can understand, the 644 permission number will only grant read and write (6) permissions to the owner (1st digit). Further, the read (4) permission is assigned to all group members (2nd digit) and other users (3rd digit).
How to Use Chmod 777 Command in Linux?
To run the chmod 777 command on your Linux computer or in WSL on your Windows PC, you need to follow the below syntax.
You can replace the 777 numeric value with other popular file permission combinations as well, as shown below.
To check the numeric permission value of an existing file/directory, you can use the below command:
Learn About Chmod 777 Command in Linux
So that’s everything you need to know about Chmod 777 and what it does in Linux. As mentioned above, we would not recommend giving permission to all users, especially if you are facing issues with your web server. Instead, we suggest you use the 644 or 755 file permission values, as they are not as high risk. further, to find out the 10 best Linux distros, head to our curated list. And to learn about the differences between Unix and Linux, follow our comprehensive comparison. Finally, if you have got any questions, let us know in the comment section below.