File Permissions and Access Control Lists

File Permissions and Access Control Lists

Day 6 of 90daysofdevops

What is File Permission?

In Linux, file permissions determine who can access a file or directory, and what actions they can perform on it. There are three types of permissions: read, write, and execute, and these permissions can be assigned to three different groups of users: the owner of the file, members of the owner's group, and all other users.

Ownership Types

  1. User: A user is the one who created the file. By default, the user creates the file and becomes the owner of the file. A user can create, delete, or modify the file.

  2. Group: A group can contain multiple users. All the users belonging to a group have the same access permission for a file.

  3. Other: Anyone who has access to the file other than the user and group comes in the category of other. Other has neither created the file nor is a group member.

    NOTE: Users and groups can be locally managed in /etc/psswd or /etc/group

File Permission Types

  1. Read (r) - The read permission allows you to open and read the content of a file.

  2. Write (w) - The write permission allows you to edit, remove or rename a file.

  3. Execute (x) - In Unix type system, you can't run or execute a program unless execute permission is set.

NumericPermissionSymbolic
7read, write and executerwx
6read and writerw-
5read and executer-x
4read-onlyr--
3write and execute-wx
2write only-w-
1execute only--x
0no permissions---

Changing file/directory permission in Linux

  • we can modify permissions using the chmod command.

Syntax:

chmod permissions filename

We can change permissions using two modes:

  • Symbolic mode: this method uses symbols like u, g, o to represent users, groups, and others. Permissions are represented as r, w, x for read write and execute, respectively. You can modify permissions using +, - and =.
#Lists file according to modified date recursively
ls -ltr  

#All permission to user
chmod u+rwx file1.txt  

#Read & write permission to group user
chmod g+rw file1.txt

  • Absolute mode: this method represents permissions as 3-digit octal numbers ranging from 0-7.

      #Lists file according to modified date recursively
      ls -ltr 
    
      #Changing permission of the file
      chmod 766 file1.txt 
    
      #Read-only permission
      chmod 444 file1.txt
    

Changing Ownership and Group

  • You can change the ownership of a file or folder using the chown command.

Syntax:

chown <user_name> <file/directory name>

  • You can change the ownership of a file or folder using the chgrp command.
chgrp <group_name> <file/directory name>

NOTE:

Wheel Group:

-- Wheel is a system group that by default has sudo privileges if we add any member to that group then that user gets sudo privileges.

Syntax:

~ useradd

~ gpasswd -a wheel

** By default all member of the wheel group got sudo privileges


Access Control List

  • Access Control List (ACL) is a mechanism that extends the traditional Unix permissions system, allowing for more granular control over file and directory access.

  • The Linux ACL system consists of two sets of permissions: the standard Unix permissions and the ACL permissions. The standard Unix permissions are based on three categories: owner, group, and other, with permissions being either read, write, or execute. ACL permissions, on the other hand, are based on a set of rules that define who can access a particular file or directory and what level of access they have.

To get the ACL in the machine, we have to install it

apt-get install acl
  1. To check ACL permission:

    SYNTAX: getfacl <file/directory name>

  2. To add an ACL permission to a User:

    SYNTAX: setfacl -m u:<user_name>:permissions /path_of_file

  3. To remove ACL permission from a user

    SYNTAX: setfacl -x u:<user_name> /path_of_file

  4. To set ACL permission to Group

    SYNTAX: setfacl -m g:<user_name>:permission /path_of_file

  5. To remove ACL permission from a group

    SYNTAX: setfacl -x g:<user_name>: /path_of_file

  6. To remove all ACL Permission

    SYNTAX: setfacl -b /path_of_file

Thank You,

Abhisek Moharana