How to change File Permission in Linux – Primary Permission

      Comments Off on How to change File Permission in Linux – Primary Permission

Primary permission is the permission most of the time we would use. This is used to give basic read, write and execute permission which can be applied to a file or directory

==> This primary permission is nothing but chmod [change modification] permission, here most of the time we would use numeric chmod permission.

==> We can give chmod permission in two ways, one is numaric and another one is by using symbol… Whe come to numaric,

read ( r )= 4, write ( w )= 2, execute ( x )=1, 0 = no permission

rwx = 421 = 7 –> It can be apply for user(owner) or group or other users

==> How to apply this to directory,

# mkdir /test

# chmod 750 /test

# ll
drwxr-x--- 2 root root 4096 Oct 3 18:27 test/

==> Here, d indicates that it is a directory and permission is rwx for owner and r-x for group which is root here and — no permission for other users, so when ever other users try to access this directory they will get permission denied,

[email protected]:~$ ll /test/
ls: cannot open directory '/test/': Permission denied

=> Users from the root group can access it but they can’t create directory or files inside because they don’t have write permission

[[email protected] devopstree ~]$ ll /test/
total 4
drwxr-xr-x 2 root root 4096 Oct 3 13:11 ok
[[email protected] devopstree ~]$ mkdir /test/fail
mkdir: cannot create directory ‘/test/fail’: Permission denied

=> Only root can access this directory, to change group we should use,

# chgrp admin /test
# chown root:admin /test

=> When we use -R with the chown command it will apply for all file and directory inside the test directory.

==> We can use symbols to give access, symbols are

read ( r ), write ( w ), execute ( x ), delete ( - ), add ( + ), user ( u ), group ( g ), others ( u ), all ( a ), (,), ( = )
# chmod ugo=r /test

=> It will provide only read operation to owne, group and other users.

# chmod u=rwx,g=rw,o=r /test

=> It will give full access to owner, read and write access to group and only read operation to others. You should be care because by default root has each and every access.

=> So user fron the root group also can’t go into the test directory using cd command because it has no execution permission,

[[email protected] devopstree ~]$ cd /test/
-bash: cd: /test/: Permission denied

==> We can open[cd] a directory only if we have execution permission.

==> We can create or delete [mkdir, rm] a directory or file inside the directory only if we have write permission.

==> We can view[la] the dirctory or file only is we have read permission.

Sharing is caring!

About Dinesh Sobitharaj C

An IT professional having multiple years of experience in IT Infrastructure planning, System integrations, Project implementation and delivery. Devops Enthusiast skilled with broad ranges of technology adoption. Well versed with Cloud Computing and Application Service Offerings such as SaaS/PaaS/IaaS. Expert in aligning business goals, mission and process to architect innovative solutions and strategies.