Linux File/Folder Permissions
Linux File & Folder

Linux File/Folder Permissions

sudo chmod -R 777 [Path:/media/folder/files]

Explained Command:

SuperUserDo ChangeMode -Recursively OwnerGroupUser [Path of File or Directory or Drive]

Every file and folder contain a 8-bit data that control the permissions. At its basic binary form, it will be “000”, which means no permissions of any form is granted. When you set a “Read” permission, it will add 4-bit to the data, making it “100” (in binary format) or a “4” in the usual decimal format. Setting a “Write” permission will add 2-bit to the data, making it “010” and “2” in decimal form. Lastly, setting an “Execute” permission adds 1-bit to the data, which will result in “001”, or “1” in decimal form. In short:

Read is equivalent to ‘4’.
Write is equivalent to ‘2’.
Execute is equivalent to ‘1’
When we want to set permissions, we just add up the number. For example, to set the permissions to read and write, we will use ‘6’ (4 + 2) for the permission. For read, write and execute, we will use ‘7’ (4 + 2 + 1) for the permission. Here’s the different permutation:

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

Depending on the permissions you want to grant to the file, you just set the number accordingly.

What about the 3 digits ‘777’? Well, the first digit is assigned to the Owner, the second digit is assigned to the Group and the third digit is assigned to the Others. So for a file with ‘777’ permission, everyone can read, write and execute the file. Here are some of the commonly used permissions:

755 – This set of permission is commonly used in web server. The owner has all the permissions to read, write and execute. Everyone else can only read and execute, but cannot make changes to the file.

777 – Everyone can read write and execute. In a web server, it is not advisable to set ‘777’ permission for your files and folders as it allows anyone to add malicious code to your server. However, in some cases, you will need to set the 777 permissions before you can upload any file to the server (For example, uploading images in WordPress)

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.



Key Terms:

  • Linux File Permissions
  • ,
  • Linux Folder Permissions

Related Article

install-jenkins-ubuntu

How to Install Jenkins on Ubuntu 22.04 or 20.04 Linux

Learn the steps and commands to install Jenkins software on Ubuntu 22.04 LTS Jammy JellyFish or 20.04 Focal Fossa Linux […]

file sharing Windows and Linux

File Sharing between Windows and Linux

Contents1 Overview2 Install Samba3 Stop Samba daemon4 Back up Samba config file5 Create new Samba config file6 Create Samba shares […]

MySQL

MySQL Error: : Access denied for user

MySQL Error: : ‘Access denied for user ‘root’@’localhost’ Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro. Add skip-grant-tables […]