📜Day 6 - File Permissions and Access Control Lists
Table of contents
The concept of Linux File permission and ownership is important in Linux. Here, we will be working on Linux permissions and ownership and will do tasks on both of them. Let us start with the Permissions.
📜Create a simple file and do
ls -ltr
to see the details of the file⚔Understanding the three Permission categories
a. 🦹♀️Owner: The owner is the individual who created the file or directory. The owner has the highest level of control, including the ability to modify permissions, change ownership, and delete the file.
b. 👦🧒👨🦱Group: Every user in a Linux system belongs to at least one group. The group permissions apply to all users within that specific group, providing a convenient way to manage access for multiple users simultaneously.
c. 💂♂️Others: This category includes all users who are not the owner or part of the group associated with a file or directory. These permissions affect everyone else on the system.
📏Changing Ownership with "chown":
The "chown" command is used to change the ownership of a file or directory. For instance:
chown new_owner:new_group filename
Example: Suppose you have a file named "example.txt" currently owned by the user "user1" and the group "group1." To change the ownership to "user2" and the group to "group2," you would use the following command:
chown user2:group2 example.txt
After running this command, the ownership of "example.txt" would be transferred to "user2" and the group ownership to "group2."
It's important to note that the user executing the chown
command must have the necessary permissions to change ownership of the file or directory.
📏Changing Group Permissions with "chgrp":
To modify the group ownership of a file or directory, the "chgrp" command is used:
chgrp new_group filename
📏Modifying Other Users' Permissions with "chmod":
To modify the group ownership of a file or directory, the "chgrp" command is used:
chmod 777 filename # This will give file permission for Owner,group,others as READ WRITE and EXECUTE # read-4,Write-2,execute-1
📏Checking Permissions with "ls -ltr":
After modifying permissions, the "ls -ltr" command can be used to display detailed information about files and directories, including ownership and permissions.
$ ls -ltr -rw-r--r-- 1 user1 group1 1024 Jan 1 10:00 filename
In this example, the file "filename" is owned by "user1," belongs to the "group1" group, and has read and write permissions for the owner but only read permissions for the group and others.
📏Advanced File Permissions with ACL: Access Control Lists (ACL) provide a more granular approach to file permissions, allowing additional rules beyond the standard owner, group, and others. The "getfacl" command retrieves ACL information, while "setfacl" is used to define new ACL rules.
Example:
$ getfacl filename $ setfacl -m u:user2:rw- filename
This example grants read and write permissions to "user2" specifically, supplementing the traditional owner, group, and others permissions.
🚧Conclusion:
Understanding and effectively managing file permissions is fundamental for maintaining a secure and organized Linux system. With the "chown," "chgrp," and "chmod" commands, administrators can control access on a per-user and per-group basis. Exploring ACL provides even more flexibility for intricate permission setups, enhancing the security of sensitive data within a Linux environment.
this blog will help you discover new insights and learn something very exciting to do hands on.🙏
😊Happy Learning : )
Subscribe to my newsletter
Read articles from Vivek Ashok Moudekar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Vivek Ashok Moudekar
Vivek Ashok Moudekar
👋 Hello there! I'm Vivek, a DevOps enthusiast with a keen interest in streamlining software delivery. I hold a Master's degree in Computer Applications and have a solid foundation in key technologies such as Linux, Git, Docker, Kubernetes, and AWS. 💻 My passion lies in automation, ensuring efficient and seamless processes throughout the software development lifecycle. I thrive on creating robust CI/CD pipelines that empower teams to deliver high-quality software with confidence. 🚀 Beyond the code, I enjoy the ever-evolving world of DevOps and the challenges it brings. Join me on this journey as I explore new ways to enhance software delivery and foster a culture of continuous improvement. Let's connect, collaborate, and make the world of DevOps even more exciting together