File permission in linux

If you are working on a multi-user operating system then permitting a file (file permission) must be necessary. As we know that Linux is a multi-user operating system and many users can access it simultaneously. Although a lot of security features are available in Linux. But file permission gives tremendous power to a Linux-based operating system. So basically it is a way by which we can restrict users to access any file and directory.

To understand the concept we need to understand the basics. Inside Linux, we have three types of users or owners –

  1. Owner – Person who created a file becomes its owner.
  2. Group – Group can contain multiple users. Everyone belongs to the same access permission
  3. Others – This person has neither created the file, nor he belongs to a user group.

In Linux, We have only 3 basic permissions –

  1. Read (r OR 4)
  2. Write (w OR 2)
  3. Execute (x OR 1)

We have two notations to permit the file. The first is by character and the second is by a numeric value. Here Read can be denoted as r or 4.

Basic implementation of linux permission
permission

Now you can see in the image how we can approach giving the permissions. We have chmod command to permit any file.


# First way
chmod <permission> <file>

# Second way 
chmod <who>=<permission> <file>

# Third way 
chmod <who>+/-<permission> <file>

Now let us take an example


# Current file permission is rwxrwxrwx
# Now we need to change permission and the only owner can read, write and execute a file

chmod rwx------ readme.txt
chmod g= readme.txt
chmod o= readme.txt

chmod go-rwx readme.txt

You May Also Like

About the Author: Pankaj Bisht