File permission in linux

file-permission

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 simultaneously. Although a lot of security feature available in Linux. But file permission gives tremendous power to a Linux based system. So basically it is a way by which we can restrict to users to access any file and directory.

To understand the concept we need to understand the basic. 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 same access permission
  3. Others – This person has neither created the file, nor he belongs to a usergroup.

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 notation to permit file. 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 to giving the permissions. We have chmod command to permit to any file.



# First way
chmod <permission> <file>

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

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

Now 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