Understanding File Permissions

File Persmissions

There are two parts to the file control mechanism, namely Classes and Permissions

  • Classes determines who can access the file
  • Permissions determines the kind of action the user can do to the file

There are 3 Classes - Owner, Group, Others.

  • The Owner is the creator of the files/folers
  • Group contians a group of users who share the same permissions and user privilege
  • Others means the general public

There are 3 types of actions the you can perform on a file/folder

  • Read
  • Write
  • Execute

What's about the number?

Every file and folder contain a 8-bit data that control the permissions

  • Read is equivalent to '4'
  • Write is equivalent to '2'
  • Execute is equivalent to '1'

For example, read, write and execute, we will use 7(4+2+1) for the permission.

  • 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

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.

  • 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.