#Day6:- 90 Days DevOps Challenge @ File Permissions and Access Control Lists In Linux

#Day6:- 90 Days DevOps Challenge @ File Permissions and Access Control Lists In Linux

Securing Your Files: File Permissions and Access Control Explained

Β·

5 min read

🌟 Welcome to the world of Linux File Permissions and Access Control Lists! 🌟

In the Linux world, file permissions play a crucial role in maintaining security and controlling user access to files and folders. Think of file permissions as digital guardians, deciding who gets to access your files and what actions they're allowed to perform. πŸš€

Picture it like a treasure chest with special locks – only those with the right keys can open it and manipulate its contents. In this blog, we'll unravel the mystery behind Linux file permissions and explore the superpowers of Access Control Lists (ACLs). Get ready to equip yourself with the knowledge to safeguard your files like a true Linux hero! πŸ›‘οΈπŸ”πŸ’»

πŸ“‚ Linux File Permissions Made Fun! πŸ“‚

In Linux, files and folders have special permissions to control who can do what with them. There are three categories of users:

  1. πŸ‘‘ Owner: The owner of the file or folder.

  2. πŸ‘₯ Group: The group that owns the file or folder.

  3. πŸ‘€ Others: All users outside the owner and group.

Each category can have three types of permissions:

  1. πŸ” Read (r): Allows users to view the content of a file or list the contents of a folder.

  2. ✏️ Write (w): Permits users to modify the content of a file or add/remove files within a folder.

  3. πŸƒβ€β™‚οΈ Execute (x): Grants users the ability to execute a file as a program or enter/traverse a folder.

Now, let's see some examples of how to change file permissions:

πŸ‘‘ Changing Ownership with 'chown' πŸ‘‘

To change the owner of a file named "example.txt" to the user "ubuntu," use:

chown ubuntu example.txt

πŸ“œπŸ“œLet's understand with an easy Example:-

:- So as of now I have created the file (example.txt) and currently the ownership is set as a root and will change it with the help of the chown commandπŸ‘¨β€πŸ’».

:- Now I have changed the ownership from "root" to "ubuntu". 🐧πŸ₯

πŸ‘₯ Changing Group with 'chgrp' πŸ‘₯

To change the group ownership of "example.txt" to group "developers," use:

chgrp ubuntu example.txt

πŸ“œπŸ“œLet's understand with an easy Example:-

:- We can able to change the group to any file or folder With the help of chgrp command, In the below image current group is rootπŸ‘¨β€πŸ’».

:- Now I have changed the group πŸ‘― from "root" to "ubuntu".

πŸ” Modifying Permissions with 'chmod' πŸ”

You can use either symbolic notation or octal notation to modify permissions.

  1. 🧩 Symbolic Notation 🧩
  • '+' adds permissions

  • '-' removes permissions

  • '=' sets permissions explicitly

For example, to give the group write and execute permissions to "example.txt," use:

chmod g+wx example.txt

πŸ“Έ In the image below, I've modified the file permissions to grant the group write and execute permissions. βœοΈπŸ’»πŸ”‘

  1. 🎲 Octal Notation 🎲

Use a three-digit number (0-7) to represent permissions:

  • 0: No permissions (---)

  • 1: Execute-only (--x)

  • 2: Write-only (-w-)

  • 3: Write and execute (-wx)

  • 4: Read-only (r--)

  • 5: Read and execute (r-x)

  • 6: Read and write (rw-)

  • 7: Read, write, and execute (rwx)

Example: To set read, write, and execute permissions for the owner and read-only permissions for the group and others, use:

chmod 755 example.txt

πŸ”“Access Control Lists (ACLs) in Linux πŸ”“

In Linux, file permissions are essential for controlling who can access, modify, or execute files and folders. However, there are situations where the standard permissions might not provide enough granularity. This is where Access Control Lists (ACLs) come to the rescue! ACLs allow us to fine-tune permissions, providing more flexibility and control over access rights.

πŸ‘“ Using 'getfacl' to View ACLs πŸ‘“

To see the ACLs associated with a file or folder, we can use the 'getfacl' command. It displays a detailed list of users and groups with their respective access permissions.

getfacl <file/directory>

πŸ“œπŸ“œNOTE: Please check the image below. If you don't see ACL listed, don't worry! We can easily install it by running the command: sudo apt install ACL. Once installed, you'll be all set to use the respective commandsπŸ‘¨β€πŸ’».

πŸƒβ€β™‚οΈπŸ’¨Re-Run the getfacl command:

For instance, if we run 'getfacl example.txt,' we might see something like this:

The output shows the default owner and group permissions, as well as any additional ACL entries.

πŸ”§ Using 'setfacl' to Modify ACLs πŸ”§

The 'setfacl' command empowers us to modify ACLs for specific users and groups. For example, let's say we want to grant read, write and execute permissions to "ubuntu" for the file "example.txt":

setfacl -m u:ubuntu:rwx example.txt

πŸ“· In the image below πŸ‘‡, you'll notice that the permissions of the Ubuntu user have been πŸ”€ changed!

After executing the above command, the ACL for "example.txt" would be updated to include "ubuntu" with read, write and execute permissions.

πŸ πŸ”‘Conclusion 🏁

Understanding Linux file permissions is like giving different keys to people for accessing a room. The owner, group, and others have their keys, each with different powers (read, write, execute). We can use the 'chown,' 'chgrp,' and 'chmod' commands to manage basic permissions.

πŸ§™β€β™‚οΈβœ¨However, in scenarios where we need more nuanced control, Linux offers the magical world of πŸ”ACLs through 'getfacl' and 'setfacl.' πŸ”ACLs enable us to provide specific access rights to individual users and groups, enhancing security and flexibility.

Feel free to reach out if you have any questions or need further assistanceπŸš€ by following me on Hashnode, LinkedIn (linkedin.com/in/mahesh-verma-441178250), and GitHub (https://github.com/maheshverma123)

Β