Understanding file permission in Linux

Posted By Vipul Pandey | 21-Sep-2018

Introduction:

This blog will help you with the permission management of the Linux as a user and handling with them effectively and efficiently. Linux stores the data in the filesystem so it is necessary to have the understanding of the file system and management correctly and changing according to our requirement.

Basic Permission File :

In the Linux, each and every file and directory is divided into 3 permission groups
Owner: The owner permission applies to the creator of the file or directory 
Group:  This permission is applicable
to the group that has been given permission to the directory or file
User: This permission applies to all the users of the application.

How to view the permission 

In the terminal or terminator(if installed) type

 ls -l 

Note: if you want to see all the commands of the Linux then you can simply type 

man ls ,man whoami etc 

The Linux permission shows the output in such a manner

-rw-rw-r--  1 vipulpandey vipulpandey 16310280 Sep 13 12:04 filePermission.txt
drwxr-xr-x  3 vipulpandey vipulpandey     4096 Aug 28  2017 gradle 

In the above 
The first character is indicated as

directory or folder in Linux if d has prefixed it a drive.
The next following 3 set of character(
rwx) is permission of owner, group and user respectively.
The r indicates read, w indicates write and x indicates execute permission.
This
vipulpandey vipulpandey is owner and group of the file or folder

Types of Permission in system
Each folder or file in Linux has 3 basic permission types
 Read: This indicates who can read the content of the file 
 Write: This indicates users who have the permission to write in the file or change its content.
 Execute:  This permission is required to perform any execution any modification in the system.

Changing the permission or Changing the ownership

To change the permission in linux we need to use chmod command while to change the ownership we need to use chown command

in the above the file owner is vipulpandey so if we need to change the permission to any other user lets say ABC user so we can simply use 

sudo chown ABC:vipulpandey fileName/directoryName 

Binary values of permission:

The permissions of files are as rwx for owner group and user so if we need to change the permission so we need to use the following command:

The binary values are written in form
r 4
w 2
x 1 

The combined permission is the sum of the above binary values like to add read and write permission so we need to add the values of the above (read 4+write 2) =6
we can use

chmod +666 file/folder so if we need to add the read permission to any files we can simply use:

 chmod + 444 file/folder 

The three values are applicable for owner group and user.
to add read

permission only to the owner to any file

 chmod + 400 file/folder 

to add the same permission in character format 

 chmod +r file/folder  

since there are 3 'r' permission in the command, so the first will be applicable to the owner only 
to add the whole

permission to any file

 chmod 777 file/folder or chmod +rwxrwxrwx  

 

 

 

 

 

 

 

 

Request for Proposal

Recaptcha is required.

Sending message..