๐Ÿ˜Day 6: Master File Permissions and Access Control Lists

ยท

3 min read

๐Ÿ˜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 include d for directories, l for symbolic links, etc.).

  • The next three characters rwx represent 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:

  1. Changing Permissions:

     chmod u+x filename
    

    This command adds execute permission to the owner of the file "filename".

  2. Viewing Permissions:

     ls -l filename
    

    This command shows the detailed listing of the file "filename," including its permissions.

  3. Changing Ownership:

     chown user:group filename
    

    This command changes the owner and group of the file "filename" to the specified user and group.

  4. Changing Group:

     chgrp group filename
    

    This command changes the group ownership of the file "filename" to the specified group.

  5. Symbolic Representation:

     chmod u=rw,g=r,o=r filename
    

    This 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! ๐Ÿ˜Š

ย