Chmod 777 – Learn Linux Permissions easy way and fix Problems
“You don’t have permission to upload a file on the server” if you have faced this error in your life, then you are at the right place. The Linux/ Unix permissions are a very important part of package management. In this article, we learn how to fix the permission issues on servers and understand the Linux permissions in detail.
What does chmod 777 command mean?
To answer the above-mentioned question we need to understand Linux permissions in depth. In the Linux/ Unix or Mac systems each and every file or folder is owned by a specific user and group. After Understanding the permission structure we can make necessary changes and avoid any problems on the desktop machines or Servers. These permissions are divided into following user types
- File Owner
- Group Members
- Other Users
Now each of the user types has specific permission parameters and we need to learn them in the following order to set permissions accordingly.
- Read Permissions – If any file or folder has read permission, then we cannot modify it. We can only read the content from the file.
- Write Permission – Files or folders having to Write Permission can be modified by the users who own then or the ones belonging to the authorized Linux groups.
- Execute Permission – Files having Execute Permission can be executed in the system.
Now if we look at this image then we can under the permission classes properly.
Now in the image, we can clearly see that the user “Me” owns the folder, hence it can create and delete contents from it. The group “appadmin ” has read and write permissions and all “Other” users have access permissions.
Let’s understand the meaning of “777” in the file permission set. The Linux Numeric permission set consists of numbers starting from “0” to “7”. Each and every number represents the permission type, which is the following.
The write, read, and execute permissions have the following numeric value:
r(read) = 4
w(write) = 2
x(execute) = 1
- no permissions = 0
When we set permissions for each user we add up numbers. Let’s say we have to give read and write permission to “Other” users then, our numeric value is going to be (4+2), which is 6. Here are the different combinations of the permissions.
0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute
According to the requirement, we can add this number with “chmod” command. The Linux/ Unix and Mac os gives us the option to use 3 digit combination like “777” and also 4 digit options like 0777. These 4 digit numbers have the following values.
- no changes = 0
Never use chmod 777 on the files or folders. This command gives full rights to everyone, they can read, write, update contents on the file. This is a huge security risk, here are some of the best Linux permission practices that we should follow on the Linux Server to maintain security.
- 755 – This set of permission should be used on a web server. The owner has all the permissions to read, write, and execute. Everyone else has only read and execute, they cannot make changes to the file.
- 644 – Only the owner can read and write. Everyone else can only read. No one can execute the file.
- 655 – Only the owner can read and write, but not execute the file. Everyone else can read and execute, but cannot modify the file.
However, 777 might be required in some cases where file uploading feature is enabled for other users as well. The application should allow only authenticated users to upload files to maintain server security. The best practice should be to use “chown” command to change the ownership of a folder or a file for restricted operations.
The best example of the Linux “chmod” command is the following for the files.
chmod 777 /var/www/html/filename.txt
For recursive permissions on the Directories, execute the following command.
chmod -R 777 /var/www/html/
If you are making changes on the Linux server or even on the Desktop Machine. Please make sure you understand the permissions properly, else it can cause huge problems. If this article helped you feel free to share this article.
If you like this article check out how to install SQL Server 2017