File Permissions and Access Control Lists

The concept of Linux File permission and ownership
๐ File Permissions:
Linux file permissions control the access rights to files and directories on the system.
They are represented by a combination of letters and numbers.
The permission string consists of three sets of characters, each set indicating permissions for the file owner, group, and others.
The three basic permissions are:
๐ Read (r) - Allows viewing the contents of a file or listing the contents of a directory.
โ๏ธ Write (w) - Permits modifying or deleting a file or creating new files in a directory.
๐ซ Execute (x) - Grants the ability to run a file as a program or access a directory.
To display permissions, use the command:
ls -lorls -alfor more details.
๐ฅ File Ownership:
In Linux, every file and directory is associated with an owner and a group.
The owner is the user who created the file or directory, and the group is a collection of users with similar permissions.
Ownership can be changed using the
chowncommand and modified along with permissions usingchmod.
๐ Changing Permissions:
Permissions can be changed using numeric or symbolic notation.
Numeric notation assigns a value to each permission: 4 for read, 2 for write, and 1 for execute. The sum of these values represents the desired permission (e.g., 755 means rwx for the owner, rx for the group and others).
The symbolic notation uses letters (u for user/owner, g for group, o for others) and symbols (+ for add, - for remove, and = for set exactly) to modify permissions (e.g.,
chmod u+x file.txtadds execute permission for the owner).
โ Common Permission Settings:
644: rw-r--r-- - Owner can read and write, group and others can read only.
755: rwxr-xr-x - Owner can read, write, and execute, group and others can read and execute.
๐ก๏ธ Special Permissions:
The Set-User-ID (SUID), Set-Group-ID (SGID), and Sticky Bit are special permission settings.
SUID allows users to execute a file with the file owner's permissions, useful for specific system tasks.
SGID allows files to run with the group's permissions, helpful for shared directories.
Sticky Bit prevents users from deleting or renaming files owned by others in a directory.
These permissions and ownership play a crucial role in maintaining security and managing access to files and directories in a Linux system.
Example:
Let's assume you have a file named "mast-file.txt" in your current directory, and you want to change the permissions for the owner. The current permissions might look something like this when you run ls -ltr:

Now, let's change the owner's permissions using the chmod command. For this example, let's give the owner read, write, and execute permissions (rwx):
chmod u+rwx mast-file.txt
Now permissions are changed

Please note that you can use various combinations of letters or numeric values with chmod to set the desired permissions for the owner, group, and others. The above example is just one way to change the owner's permissions. Always be cautious when modifying permissions to ensure security and proper access control on your system.
Access Control Lists (ACLs)
what is ACL?
Access Control Lists (ACLs) are an extension to standard Linux file permissions that provide more fine-grained control over access to files and directories. While standard permissions (owner, group, others) allow for basic access management, ACLs allow you to define permissions for specific users and groups beyond the traditional three categories.
The getfacl command is used to view the ACLs of a file or directory, while the setfacl command is used to set or modify the ACLs. Here's a brief overview of how these commands work:
getfacl:Syntax:
getfacl [file/directory]Example:
getfacl mastfile.txt
The getfacl command displays the ACL entries for a specific file or directory in a human-readable format. It shows both the standard permissions (owner, group, others) and any additional ACL rules defined for individual users or groups.
setfacl:Syntax:
setfacl [options] [file/directory]Example:
setfacl -m u:ubuntu:rw mast-file.txt
The setfacl command allows you to set or modify ACLs for a file or directory. It can be used to add or remove specific access rules for users or groups.
Some common options for setfacl include:
-m: Modify the ACL (add or modify entries).-x: Remove specific ACL entries.-b: Remove all ACL entries.-d: Set a default ACL for directories (used for new files created within the directory).
When setting ACLs, you need to specify the user or group for which you want to define permissions, along with the access rights (read, write, execute).
Please note that ACLs are an advanced feature, and they require proper understanding and careful usage to ensure security and avoid unintended consequences. Not all file systems support ACLs, so make sure your file system supports them before using these commands.
Before using setfacl, you should check the existing ACLs using getfacl to understand the current access control settings on a file or directory. Always exercise caution when modifying ACLs to prevent potential security issues or accidental changes to access permissions.
Thanks for reading ๐ | Stay Connected
LinkedIn | https://www.linkedin.com/in/akashpawar11/


