Tuesday, 10 September 2019

PERMISSIONS FOR FILES IN LINUX

PERMISSIONS FOR FILES AND DIRECTORIES IN LINUX :

PERMISSIONS FOR FILES :-
            There are three classes of file permissions for the three classes of users :
1. The owner( or user) of the file
2. The group the file belongs to, and all other users of the system.

$ls -l
-rwxr-xr--

The first three letters of the permissions field refer to the owner's permissions
      rwx --- owner can have the read , write, execute the file.
The second three to the members of the file's group and the last to any other users.
The  second group of of three characters, r-x, indicates that members of the group can read and execute the file but cannot write it, The last three characters, r-x, show that all others can read and execute  the file but not write to it.
If you have read permission for a file, you view its contents. Write permission means that you can alter its contents. Execute permission means that you can the file as program.

PERMISSIONS FOR DIRECTORIES :
     For directories, read permission allows users to list the contents of the directory, write permission allows users to create or remove files or directories inside that directory, and execute permission allows users to change to this directory using the cd command or use it as part of a path name.           


CHANGING FILE PERMISSION

chmod is the command to change file permission's or directory permission's.

Syntax
               $chmod [who] [+/-/=] [permissons] filename
In using, first specify which permissions you are changing, second specify how should be changed, Third, specify the file permission type :
                       
                 u for user or owner
                 g for group
                 o for others

                  +    for to add permission
                  -     for to substract permission
                  =     for to assign permission (i.e., add specified permission and take away all other                                     permissions, if present)

                  r for to read
                  w for write
                  x for to execute

                  Eg :- add write permission to group members on devops file
                           $ chmod g+w devops

                   Eg :- add execute permission to others and owner on devops_team file
                            $ chmod u+x, o+x devops_team
                             or
                            $ chmod o=r,g-w devops_team

Another form of the chmod command lets you set permissions directly, by using a numeric(octal) code to specify them .
               This code represents a file's permissions, by three octal digits: one for owner permissions, one for group permissions, and one for others. These three digits appear together as one three- digit number.


                                        PERMISSION                      WEIGHT
                                                Read                                     4
                                                 write                                    2
                                                 Execute                               1
                                                 Read and write                    6
                                                 Write and execute               3
                                                 Read and execute                5
                                                 Read, Write and execute     7
           
Eg :-
         $ chmod 700 devops_team
          The above command sets read, write and execute permissions for the owner only and allows no one else to do anything with the devops_team file.


Eg :-
         $chmod 754 devops_team
           The above command sets all permisions for owner and sets only read and execute to group and sets only read permission to others on devops_team file.

































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

No comments:

Post a Comment

Streamlining the usage of GITHUB

Streamlining the usage of Github with Commands 1. Start a new git repository under one directory locally In this step, we need to bui...