😍Day 6: Master File Permissions and Access Control Lists

💡 Table of Contents
✅ File Permissions with Examples
✅ Access Control Lists (ACLs)
✅ Conclusion
🚀 File Permissions with Examples
In Unix-like operating systems (such as Linux), file permissions control who can read, write, and execute a file. These permissions are denoted by a series of letters or symbols visible when viewing the file’s properties. Here’s an overview of file permissions:

Read (r): Allows a user to view the contents of a file.
Write (w): Allows a user to modify or delete the contents of a file.
Execute (x): Allows a user to run a file if it’s a program or script.
These permissions apply to three entities:
Owner: The user who owns the file.
Group: Users who are part of the same group as the file.
Others: All other users.
Permissions are represented as a sequence of 10 characters. The first character represents the file type, and the remaining nine represent the permissions for the owner, group, and others. Here's an example:
- rwx r-- r--
The first character
-indicates a regular file (other types might includedfor directories,lfor symbolic links, etc.).The next three characters
rwxrepresent the owner’s permissions (read, write, and execute).The following three characters
r--represent the group's permissions (read-only).The last three characters
r--represent others' permissions (read-only).
Examples:
Changing Permissions:
chmod u+x filenameThis command adds execute permission to the owner of the file "filename".
Viewing Permissions:
ls -l filenameThis command shows the detailed listing of the file "filename," including its permissions.
Changing Ownership:
chown user:group filenameThis command changes the owner and group of the file "filename" to the specified user and group.
Changing Group:
chgrp group filenameThis command changes the group ownership of the file "filename" to the specified group.
Symbolic Representation:
chmod u=rw,g=r,o=r filenameThis command sets read and write permissions for the owner, read-only for the group, and read-only for others.
🚀 Access Control Lists (ACLs)
Access Control Lists (ACLs) provide extra flexibility for setting permissions on files and directories in a file system. ACLs allow specifying access rights for individual users or groups, beyond the basic owner-group-others scheme.
Use of ACLs: Imagine you need to grant specific read or write access to a user who is not part of your group. Without adding the user to the group, you can use ACLs to grant the required permissions.
Checking ACLs: To check the ACL for a file or directory, use the getfacl command. For example, to examine the ACLs for the file /etc/passwd, you would use:

getfacl /etc/passwd
Setting ACLs: To set or adjust the ACL for a file or directory, use the setfacl command. For instance, to grant read and write permissions to the user "newuser" on the ACL for the file /etc/passwd, use:

setfacl -m u:newuser:rw /etc/passwd
🫡 Conclusion
Understanding file permissions and ACLs is crucial for maintaining the security and proper functioning of a Linux system. File permissions regulate basic access rights, while ACLs offer more granular control, allowing precise access settings for individual users and groups.
Happy Learning! 😊
About the author
👋 Hi, I'm Ritesh Dolare, a DevOps enthusiast dedicated to mastering the art of DevOps.
Comments
Join the discussionNo comments yet. Be the first to comment.




