File & Folder permissions.

File & Folder permissions.

Day-06

What is File Permission?

File permission is a set of rules that determine the access rights of a file on a computer system. It specifies which users or groups are allowed to perform specific actions on a file, such as read, write, or execute. File permissions are a critical component of file system security, allowing system administrators to control who can access files and what actions they can perform on them. In Unix-like systems, file permissions are usually represented by a combination of letters and numbers, such as "rwxr-xr-x" or "644". The first character indicates the file type, and the next three characters indicate the permissions for the owner of the file, followed by the permissions for the group, and finally the permissions for all other users.

Types of File permission in Linux:

In Linux, there are three basic types of file permissions:

  1. Read (r) - Allows the user to read the contents of a file or list the files in a directory.

  2. Write (w) - Allows the user to modify the contents of a file or create, rename, or delete files in a directory.

  3. Execute (x) - Allows the user to execute a file or enter a directory and access its contents.

These permissions can be assigned to three different entities: the owner of the file, the group owner of the file, and all other users. In Linux, each file or directory has three sets of permissions that correspond to these entities, which are represented as three groups of characters in the permission string.

For example, the permission string "rwxr-xr-x" indicates that the owner has read, write, and execute permissions, the group owner has read and execute permissions, and all other users have read and execute permissions.

In Linux, there are two types of representation of file permissions: symbolic notation and numeric notation.

Symbolic notation

  1. To who the permissions apply to:

    • "u" for the owner of the file

    • "g" for the group owner of the file

    • "o" for others (everyone else)

    • "a" for all (equivalent to "go")

  2. The operation to be performed:

    • "+" to add a permission

    • "-" to remove a permission

    • "=" to set the permission to the exact value

  3. The permission itself:

    • "r" for read permission

    • "w" for written permission

    • "x" for execute permission

Numeric notation:

Numeric notation: This is a three-digit number that represents the file permission settings for the owner, group, and others. Each digit is calculated by adding up the numeric values of the corresponding permission settings. The read permission has a value of 4, the write permission has a value of 2, and the execute permission has a value of 1. The digits represent the sum of these values for each group.

For example, the permission string "rwxr-xr-x" can be represented as the numeric value "755", which indicates that the owner has permission to read, write, and execute the file (4+2+1=7), and the group and all other users have permission to read and execute the file (4+1=5).

File permissions can be displayed either in symbols or numbers. For this tutorial, we will discuss the number format.

Permission numbers come in three to four digits. These numbers can go from 0 to 7.

The first digit is for the file owner’s permissions. The next digits represent the file’s group. The last one symbolizes other users.

The read, write, and execute permissions contain the following numerical values:

4 = r (read)
2 = w (write)
1 = e (execute)

The sum of the values represents the permissions each user class is entitled to. The sum of all the values is called the permissions digit.

Each permissions digit corresponds to a sum of 0, 1, 2 and 4:

7 = 4 + 2 + 1 : Read, write, and execute permission
6 = 4 + 2 + 0 : Read and write permissions
5 = 4 + 0 + 1: Read and execute permissions
4 = 4 + 0 + 0 : Read permission ONLY
3 = 0 + 2 + 1 : Write and execute permissions
2 = 2 + 0 + 0 : Write permission ONLY
1 = 1 + 0 + 0 : Execute permission ONLY
0 = 0 + 0 + 0: No permission granted

For example, if you have 760 as a set number, here are the following conditions per group. This ties back to each group's access to either a file or directory.

The file's main owner has rights to the read, write, and execute permission (7).

The file's main group can only have read and write permissions (6).