Day06: File Permissions and Access Control List🎯

Aesha ShahAesha Shah
3 min read
  • What is File Permission & ACL πŸ’β€β™‚οΈ

    File permissions and Access Control Lists (ACLs) are two mechanisms used in Unix-like operating systems to control and manage access to files and directories. They both play a crucial role in file security, but they differ in their complexity and capabilities.

File Permissions...πŸ”

File permissions are a simple and effective way to control access to files and directories. They are based on three basic permissions: read, write, and execute, which can be assigned to three different groups of users: owner, group, and others. The chmod command is used to modify file permissions.

  1. Create a simple file and do ls -ltr to see the details of the files.

    Each of the three permissions are assigned to three defined categories of users.

    The ls command in Linux is used to list the contents of a directory. The -l option is used to display the contents of the directory in a long format, which includes information such as file permissions, ownership, size, and modification time. The -t option is used to sort the files and directories by their last modification time, with the most recently modified files and directories appearing first. The -r option is used to reverse the order of the listing, so that the oldest files and directories appear first. Finally, the -ltr option is used to combine the -l, -t, and -r options, which results in a long format listing of files and directories sorted by their last modification time in reverse order.

Now see the example of file permissions. I am creating one file temp.txt and this file have permissions like below image have.

Linux permissions example explained

Now I want to give whole access to my temp.txt so I am using chmod to change the permissions.

Now temp.txt have whole permissions read, write and execute.

Access Control Lists...πŸ‘©β€πŸ’»

Access Control Lists (ACLs) provide a more flexible permission mechanism for file systems. They allow you to give permissions for any user or group to any disk resource. ACLs are used to define more fine-grained discretionary access rights for files and directories. They are designed to assist with UNIX file permissions. setfacl and getfacl are used for setting up ACL and showing ACL respectively ΒΉ.

Here are some useful commands for setting up ACL:

  1. To add permission for user: setfacl -m "u:user:permissions" /path/to/file

  2. To add permissions for a group: setfacl -m "g:group:permissions" /path/to/file

  3. To allow all files or directories to inherit ACL entries from the directory it is within: setfacl -dm "entry" /path/to/dir

  4. To remove a specific entry: setfacl -x "entry" /path/to/file

  5. To remove all entries: setfacl -b path/to/file

Let's try out the commands getfacl and setfacl

setfacl command is used to set access control lists (ACLs) of files and directories, whereas getfacl command is used to get file access control lists. For each file, getfacl displays the file name, owner, the group, and the Access Control List (ACL).

0
Subscribe to my newsletter

Read articles from Aesha Shah directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aesha Shah
Aesha Shah