Types of File permissions use in linux

File Permissions

In this post, we are going to understand what type of file permissions use in linux? and what are the commands use to give permissions for file and directory?

Let's see where we will assign these file permissions :

  • Owner of file
  • Group members
  • All other users
  • Permissions under linux are configured for each file and directory.

Structure of file permissions :

-rw- r-- r-- 1 altechadmin  users  0  Oct 31  02:33   test.txt

Let's understand the above example in detail :

  • -      =   This ' - ' indicates the type of file. 
  • rw-  =   This will indicate the permissions of file which is assigned to owner of file.
  • r--   =    This one is assigned to group of members or users.
  • r--   =   It's assigned to Others.
  • 1     =    It is shows the link count which means how many links are available that file.

       For ex. normal file like above shows 1 link count but directory by default shows 2 link count and if there is more file inside that directory then link count will be depends on available files and directories.

  • altechadmin   =  it is the owner of that file.
  • users             =  users field indicates the group of members.
  • 0                   =   Size of file.
  • oct 31           =   Creation date of file.
  • 02:33           =   Creation time of file.
  • test.txt         =   Filename. 

Three types of permissions :

 
  • Read  [r]   
  • Write [w]
  • Execute [x]

We will use above permissions to below things :

 
  • User      -->  u
  • Group   -->  g
  • Other    -->  o
  • All        -->  a

Below are the Operators used to give permissions :

 
  • + -->  Add permissions
  • -  -->   Delete permissions
  • = -->   Clear all permissions

Below table shows numeric value for permissions :

File permissions

Octal numbers and permissions

You can use octal number to represent mode/permission:
  • r: 4
  • w: 2
  • x: 1
Let's see some examples which help you to undertand it more easily.
if you want to give full permmission like read,write and execute then use below octal calculation.
  • 0+r+w+x = 0+4+2+1 = 7 

Only Read and write permission use below octal values,

  • 0+r+w+x = 0+4+2+0 = 6

 Fore read and execute permission on a file in octal is

  • 0+r+w+x = 0+4+0+1 = 5

 

Use above method to calculate permission for owner, group and others. Let say you want to give full permission to owner, read & execute permission to group, and read only permission to others then you need to calculate permission as follows:

 

  • User = r+w+x = 0+4+2+1 =  7
  • Group= r+w+x = 0+4+0+1 =  5
  •  Others = r+w+x = 0+4+0+0 = 4

So you have given permission to file is 754.

 

Now we see the command which help to change the permissions of file and directories :

Chmod command : used to set up permissions for files and directories.     

We have two ways to change the permissions of file :

         1. Symbolic way :- 

  • chmod  u-w  test.txt  [ ' - ' means remove the write permission for user ]

 

 
  • chmod ugo+w test.txt [ ' + ' means add the write perm  for all ]

       OR

  • chmod a+w test.txt [ 'a' means all user , group and others ]
 
 
  • chmod  =  test.txt    [ ' = '  means clear all permissions ]

 

 
2. Octal way :-
 
  • chmod 756  test    [ ' 7 ' = 4+2+1 = user,' 5 ' = 4+0+1 = Group,' 6 ' = 4+2+0 = Others ].
 
 
  • chmod  644  test     [ 644 is default permission for files ]
 
 
This is all you need to learn about the file permissions. if you have any query regarding this post then feel free put your comments under the comment box.
Thank you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *