Understanding and learning file permissions in Linux OS - CloudMinister

Why do we use file permission in Linux/Unix? 

 Linux is a clone of UNIX operating system, it is a multi-user operating system, which can be accessed by many users at a time.

 Because of this , it raises the question on its security, that it can be easily corrupted or any one can change or remove the crucial data.

 So, taking care of the security.

 

Linux divides authorisation level into 2 levels

 1…Ownership

 2…Permissions

 

Ownership 

 In linux the system is allocated 3 types of owner

 → First one is “User

         Owner of the file.The person who creates the file is called the owner.

→ Second one is “Group

           In a group there can be multiple users we can put multiple users in a group and assign the same file permission. 

 → Third one is “other

          Other can be anybody except user & group

  Permissions

 For every user, group & other there their is set permission

  1. Read 
  2. Write 
  3. Execute

 

User → rwx                                                                                          

Group → rwx                                            (-) → file -rw-rwxrw-

Other → rwx                                             (d) → directory drw-rwxrwxrw-

 

Read – Gives the permission to read the file,

 Write – Gives the permission to modify the file it gives the authority to add ,remove ,rename the file which is stored in the directory.

 Execute – we cannot open the file if the execute permission is not given to the file.

Example:- Understanding and learning file permissions in Linux OS

(d)/(-)

Show directory or file if directory (d) sign shows in starting

If file (-) hyphen sign show in starting

first (rwx)

Permission of user (read,write,execute)

Second (r-x)

Permission of group (read,-,execute)

Third (r-x)

Permission of other (read,-,execute)

r

r  refer to  read permission

w

w  refer to write permission

X

x  refer to execute permission

Give permission to file and directory has two way
1. Symbolic method
2. Octal method / numerical method

(chmod) command use to change permission

Default permission of file :-

Symbolic method

Symbolic method is used alphabets to set permission.

 

u

u refer to user

g

g refer to group

o

o refer to other

(+)

Use to add permission

(-)

Use to remove permission

(=)

Use to overwrite permission

 

Examples:-

Create “mydir” directory
1. add  write permissions to group on mydir (# chmod g+w mydir)

    Understanding and learning file permissions in Linux OS
2. Give only execute permission to other (# chmod o=x mydir)

Understanding and learning file permissions in Linux OS

3. Remove write permissions to user (# chmod u-w mydir)

Understanding and learning file permissions in Linux OS

Octal or numeric method

Octal method use numbers to set permission

 

0

(—)

No permission

1

(–x)

Execute permission

2

(-w-)

Write permission

3

(-wx)

Write and execute permission

4

(r–)

Read-only permission

5

(r-x)

Read & execute permission

6

(rw-)

Read & write permission

7

(rwx)

All permission

 

example:- use octal method to give permission

chmod user|group|other file/directory path
1. # chmod 755 mydir (this command give permission to mydir user have all permissions, group & other have only read and execute permission.)

Understanding and learning file permissions in Linux OS

Special permission

1. Setuid (set user id)
2. Setgid (set group id)
3. Sticky bit

1. setuid :- setuid is the permission bit that allows the user to execute a command/ program with the permission of its owner. Setuid permission are used to tell the system to run an executable file as the owner with the owner’s permission.

Symbolic method to setuid —># chmod u+s file_name (This command use to setuid bit on file)

Octal method to setuid —># chmod 4766 file_name (This command use to setuid bit using  octal method)

Remove setuid bit —># chmod u-s file_name (This command use to remove the setuid bit form file)

2. Setgid :- setgid is a bit that allows the user to execute a program with the permission of the group owner.

Symbolic method to setgid  —># chmod g+s file_name (This command use to setgid bit on file)

Octal method to setgid —># chmod 2766 file_name (This command use to setgid bit using octal method)

Remove setgid bit —> # chmod g-s file_name  (This command use to remove the setuid bit form file)

3. Sticky bits :- A sticky bit is a permission bit that is set on a directory that allows only the owner of the file within that directory or the root user to delete or rename the file. No other user has the needed privileges to delete the file created by some other user.

Symbolic method to set sticky bit  —># chmod +t file_name (This command use to set the sticky bit on file and directory)

Octal method to set sticky bit —># chmod 7660 file_name (This command use to set stickybit using octal method)

Remove sticky bit —> # chmod -t file_name  (This command use to remove the sticky bit)

Conclusion:

By following this tutorial you will learn what are the permissions as well as special permission in Linux/Unix.

Learn how to scale, manage, and optimize your applications with a SLB. Read our solution brief "Get More from Your Enterprise Network".

DOWNLOAD SOLUTION BRIEF

Get started with CloudMinister Today