What is Chmod 777? If you’re a new Linux user, you’ve probably encountered the Chmod command at some point in the beginning. Maybe someone told you to “chmod 777” to move a file to a certain folder, and it worked! So what does the chmod command do and what do the numbers mean?
This article will discuss everything you need to know about Linux file permissions. This is important to know to understand the chmod command and the numbers that correspond to certain access levels.
Whether you’re using Ubuntu, Fedora, or a more exotic Linux distribution, you need to understand when it’s okay to set permissions to 777 using the CHMOD command and when you should use a different setting.
Chmod 777 Guide
How Linux File Permissions Work
In Linux, the operating system determines who can access a given file based on the file’s permissions, ownership, and attributes. The system allows you, as the owner or administrator, to enable access restrictions to various files and directories. You can improve the security of your system by granting access only to users and programs you trust.
Understanding User Classes
A specific user and group on each file and directory. This means that there is three categories of users to which a certain level of access can be assigned. These users are categorized as follows:
You can see these groups visually in Ubuntu by right-clicking on any directory, selecting Properties and go to the permissions tongue.
The owner is the person who has all the power. They usually have full access to all files and directories and can also change other users’ file permissions.
The Group is made up of a number of users who have some level of access to a file or directory provided by the Owner. For example, a group of users can be excluded from editing a file but still be allowed to view that file.
The Other class simply represents guest users who do not belong to the other two categories. By default, your access level is generally restricted. It is up to the Owner to determine what guest users can or cannot do.
Understanding File Permission Levels
As an owner, you can assign three levels of access to your files and directories:
- Read: Gives you limited access to a file or directory. All you can do is play the file or view the contents of the directory. You cannot modify the files and you cannot delete or add new files to the directory.
- To write: Allows you to read and edit files. If you assign this level of access to a directory, you can also delete or add files.
- Course: Only important when executing or executing files. For example, you cannot run a script or program without execution permission.
By combining classes and permissions, you can control how much access a specific user has to a file or directory.
Explanation of Symbols and Permit Numbers
File permissions are represented numerically or symbolically. You can use both symbols and numbers to change file and directory permissions. The easiest way is to use numbers, but you also need to understand symbols. So let’s first look at the symbols behind file permissions.
File permission symbols
You can see your permissions for all content in a given directory by typing the following command in the terminal:
You can access any directory using the CD order. If you’re a complete beginner, check out our article on basic Linux commands.
In our example, the directory contains two other directories and a file. Permissions are written using (1+) 9 symbols which can be split into triplets for better understanding. Let’s look at the first set of permissions for the Books directory:
Let’s separate it for easier reading:
d rwx rwx rx
The first symbol is D, y means directory. It can also be a dash if it’s a file, as you can see in the third set of permissions for the Schema.docx file.
Next, we have three groups of symbols. The first group represents Owner permission levels, the second group is for the Group class, and the third represents Others.
Each set of 3 symbols means to read, write, and execute, in that order. Thus, the owner has permission to read, write, and execute all files and directories inside the test directory. Here is a visual representation:
When you see a dash instead of r, wox, it means the permission does not exist.
File authorization numbers
The digital format for file permissions is simple. Essentially, file authorization codes are three digits long:
- The first is for the owner of the file.
- The second represents the group of the file.
- The last digit is for everyone.
The numbers range from 0 to 7 where:
- 4 = read.
- 2 = write.
- 1 = run.
- 0 = no permission.
The permit number for each class is determined by adding the permit values. In other words, each digit of each class can be the sum of 4, 2, 1, and 0. Here is a complete list of permissions:
- 0 (0 + 0 + 0) = User class has no permissions.
- 1 (0 + 0 + 1) = Execute permission only.
- 2 (0 + 2 + 0) = write permission only.
- 3 (0+2+1) = write and execute permissions.
- 4 (4 + 0 + 0) = read-only permission.
- 5 (4 + 0 + 1) = read and execute permissions.
- 6 (4 + 2 + 0) = read and write permissions.
- 7 (4 + 2 + 1) = All permissions.
For example, a 644 permission means that the owner of the file has read and write permissions, while the other two classes only have read permissions. Setting permissions using the number format requires only basic math.
As you’ve probably guessed by now, a 777 permission grants read, write, and execute permissions to all three classes of users. In other words, anyone with access to your system can read, modify, and execute files. Use it only when you trust all your users and don’t have to worry about security breaches.
The 777 authorization is often used because it is convenient, but you should use it sparingly. In fact, we recommend that you never use it because the security risks are too great. An unauthorized user could compromise your system or, for example, modify your website to distribute malware.
You should give permission 755 instead. This way, as the owner of the file, you have full access to a certain file or directory, while everyone else can read and execute, but cannot make changes without your approval.
Changing File Permissions with Chmod
You can change the file permission using the chmod command. The easiest way to use this command without any other variables is:
filename chmod 777
Replace “filename” with the name of the file and its path.
Note that the only users with the power to modify file permissions are those with root access, the owners of the files, and anyone else with sudo powers.