Skip to main content

Command Palette

Search for a command to run...

(Day-6) : File Permissions and Access Control Lists 🐧

Published
β€’3 min read
(Day-6) : File Permissions and Access Control Lists 🐧
S

Motivated and goal-oriented aspiring DevOps engineer with a strong passion for optimizing software development and deployment processes

πŸ› οΈ Today, we're diving into the fascinating world of Linux file permissions and ownership! 🐧 Understanding these concepts is vital for any Linux user, as they govern who can do what with files. So, get ready to explore and master this topic. πŸš€


File Permissions:

The 'r' ,'w' & 'x' permissions in a file πŸ“–βœοΈπŸƒ:

  • To view permissions of files and directories, employ the ls -l command. Create some files and directories in your Linux machine and execute ls -l

The 'd' specifies that it's a directory. In the case of files, the output starts with an ' - '.

  • Each permission triplet indicates the access level for the owner, group, and others, respectively.

These permissions can be changed by using the chmod command.

πŸ”‘chmod command:

  • Let's create a file file1 and a directory dir2 and use the chmod command on them to change their permissions as we wish.

Lets change the permissions of file1 to 777(read write and execute on the user, the group and others as well).

The above image shows how the permissions of file1 have been changed. Lets do it for dir2; remove read access for users and add write access for groups.

πŸ”‘chown and chgrp commands :

  • The chown command, short for "change owner," is used to modify the ownership of files and directories.

  • The chgrp command, short for "change group," is used to alter the group ownership of files and directories

Example of chown:

The ownership of file1 was changed in the above example. Earlier it was owned by root but now the user 'Sarthak' owns it. Now, lets see how we can change the group of file1 too:

Example of chgrp below:


πŸ”’ Access Control Lists (ACLs):

πŸšͺ ACLs expand the basic read, write, and execute permissions with additional rules. With ACLs, you can create custom access rules for files and directories. Let's understand this using a practical scenario in our lab:

πŸ”‘getfacl command :

  • To see the ACLs of a file or directory, use the getfacl command:

      #Syntax:
      getfacl filename_or_directory
    

    The above example shows how you can get detailed information about the ACL of a file. This information can be altered as per requirement using the command setfacl.

πŸ”‘setfacl comand :

  • To set ACLs, you can use the setfacl command:
#Syntax :
setfacl -m u:user:permissions filename
setfacl -m g:group:permissions directory

#the -m denotes --modify
  • Here, u represents the user, g represents the group, and permissions can be r for read, w for write, and x for execute.

  • Let's give a user 'Binod', the write access to dir2 directory owned by root user , using the setfacl command:

  • Now let's see an instance using groups as well. Lets provide a group called 'linux' the read, write and execute access to dir2 owned by user root and also group root. See below image :


Linux file permissions and ACLs are the guardians of your precious data, ensuring its safety and privacy. With the right commands and understanding, you can control who accesses your files and what they can do with themπŸŒŸπŸš€πŸ§ Happy Learning! Ciao!!!