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

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 -lcommand. Create some files and directories in your Linux machine and executels -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
chowncommand, short for "change owner," is used to modify the ownership of files and directories.The
chgrpcommand, 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
getfaclcommand:#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
setfaclcommand:
#Syntax :
setfacl -m u:user:permissions filename
setfacl -m g:group:permissions directory
#the -m denotes --modify
Here,
urepresents the user,grepresents the group, andpermissionscan berfor read,wfor write, andxfor 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!!!



