File Permissions

  • Just like every operating system, linux comes with a set of permissions that it uses to protect files, directories and devices on the system.
  • These permissions can be manipulated to allow (or) disallow access to files and directories on different parts of the system.

Basic file permissions:

  • Let’s look at how permissions work first. Linux permissions are implemented through the properties of files and defined by three separate categories.

 

g

User:   person who owns the file.

Group:  group that owns the file.

Other:              All other users on the system.

  • Permissions in linux can be assigned one of two ways. You can use the mnemonic or a single digit to represent the permission level.

 

OperationDigit Mnemonic Description
Readr4View file contents.
Writew2Write to or change.
Executex1Run the file.

 

Default file permissions:

Umask: Universal mask is a default value that always gets dedicated from maximum  file permission allocated for every file & directory.

  • For super user umask value is # 022.
  • For Normal user umask value is $002

For super user:

  • Maximum permission of a file 666

-------------------------------Umask  (-)022

  • Default file permission ------>  644

  • Maximum permission of a directory 777

---------------------------------Umask       (-)  022

  • Default directory permission 755

Inclined to build a profession as Linux Developer? Then here is the blog post on Linux Training Online.

For Normal user:

  • Maximum permission of a file ------ 666

---------------------------------Umask   (-)_   002

-------------------------------------------------664

  • Maximum permission of a directory --- 777

    umask                ---     002

    (-)

    775

  • To see the umask # umask
  • To change the umask # umask 222
  • To view umask value from the fiel # vim /etc/ bashrc

Operators:

+        --->      To add a permission.

  •      --->            To remove a permission.

=          --->        To override the permission.

  • Here are some of the commands you can use to work with permissions:

(a) Chmod:- It is used to change the permission of a file and directory. It can be used by the owner of the file (or) by root.

Syn: Chmod [options]            [permission]   [file]

--R ---> Acts recursively.

--V ---> Provides verbose output.

EX:       1)         # Chmod         u+rw,g+r, o+x   linux

# Chmod         641      linux

2)         #chmod  ugo =rw backup

(or)

# chmod          666      backup

3)         #chmod           U-W, g-r, o-x  linux

4)         #chmod           -R         U+W, g+r, o+x linux

5)         #chmod           -R         777 unix

6)         # chmod          755      Unix

(b) Chgrp:

à By using this command we can change group of the file.

Syn:     Chgrp [options] [group name] [file]

-R ---> Recursively

-V ---> Verbose

Ex:       #ls  -l linux

#chgrp sales linux

(c) Chown:-  This command is used to we can change the owner of the file, as well as  owner & group at a time.

Syn:  Chown [options]           [user:group]    [file]

-R---> Recursively

-V---> Verbose.

EX:       #Chown raju linux                  To Change only owner.

#Chown raju: sales linux       To Change owner & group

#Chown –R ramu: color unix             Recursivly to change.

  • To view the symbolic as well as numeric mode of permission

# stat linux

  • To change the permissions in GUI mode

#navtilus &

  • Assign the permissions in GUI mode:

Right click on file -----> properties ---->  permissions.

For indepth understanding of Linux click on