File Permissions and Access Control Lists

File Permissions and Access Control Lists

ยท

4 min read

Introduction

Welcome to the fascinating world of Linux, where security and access control reign supreme! Just like you lock your diary to keep your secrets safe, Linux uses special codes to protect its files. ๐Ÿ“๐Ÿ”’ Let's dive into the exciting world of file permissions and something called Access Control Lists (ACLs) โ€“ don't worry, we'll explain everything in simple terms! ๐Ÿš€

Linux File Permissions:

File permissions play a pivotal role in securing our data and maintaining privacy. Each file and directory in Linux has three sets of permissions: one for the owner, another for the group, and the third for others. These permissions come in three flavors: read (r), write (w), and execute (x).

  1. Read (r): The ability to view the contents of a file or list the contents of a directory.

  2. Write (w): The ability to modify or delete a file or create new files in a directory.

  3. Execute (x): The ability to run a file as a program or access a directory's contents.

Linux File Permissions Explained: A Practical Approach

chmod - Command is used to change the permission of file & directory.

How do you view Linux File Permissions?

Gaining insights into file permissions is as simple as employing the ls command with the -l flag. This command conjures a detailed display of file properties, including permissions, ownership, size, and timestamps.

Manage file permissions with Alphabet:

Linux users can manipulate file permissions using a blend of alphabetic symbols and operators. The shorthand "u" represents the owner, "g" signifies the group, and "o" stands for others. To grant or revoke permissions, the plus "+" and minus "-" signs come into play.

take an example:- here,

  1. To give the owner read, write, and execute permissions:

    chmod u+wrx file1.txt

  1. To give the group write permissions:

    chmod g+w file2.txt

  1. To remove execute permission for others:

    chmod o-rwx file2.txt

Manage Linux File Permissions using Numbers:

For a more streamlined approach, Linux offers numeric values to manage file permissions. Every permission is assigned a numeric value: 4 for read, 2 for write, and 1 for execute. These values can be combined to denote specific permission configurations.

take an example:- here,

  1. chmod 750 newfile.txt

7 represents: user has permission for (Read, Write, Execute )

5 represents: group has permission for (Read, Execute )

0 represents: other has no permission.

  1. chmod 642 newfile.txt

6 represents: user has permission for (Read, Write )

4 represents: group has permission for (Read )

2 represents: other have permission for (Write ).

Command to change the ownership permission of a file or directory:

The chown command in Linux is used to change the ownership of files and directories. It allows you to transfer ownership of a file or directory to a different user or group on the system.

Only the root user (superuser) or a user with appropriate privileges can use chown.

The basic syntax of the chown command is as follows:

sudo chown <new_owner_name> <file_name>

for example :

Command to change the group permission of a file or directory:

The chgrp command in Linux is used to change the group ownership of files and directories. It allows you to transfer ownership of a file or directory to a different group on the system. Like chown, only the root user (superuser) or a user with appropriate privileges can use chgrp.

The basic syntax of the chgrp command is as follows:

sudo chgrp <new_group_name> <file_name>

for example :

To change the owner and group of a directory named new folder to the user "user1" and the group "devops" :

Before:

After :

Access Control Lists ( ACL):

An Access Control List (ACL) is an additional layer of access control that complements the traditional owner-group-other (rwx) permissions model. It allows you to define access rights for multiple users and groups on a specific file or directory. This level of granularity gives administrators more flexibility in controlling who can read, write, execute, or even delete certain files, especially in scenarios involving shared directories or complex user groups.

getfacl: getfacl is the command to show what are permission assigned to any file/folder.

Syntax:

getfacl file_name_or_directory

setfacl: setfacl is the command used to grant permission to any file/folder.

Syntax:

setfacl -m u:user:rwx,g:group:rw,o::r file_name_or_directory

Here:

  • -m: Modify the ACL entry.

  • u:user: Set the ACL entry for a specific user.

  • g:group: Set the ACL entry for a specific group.

  • rwx: Define the permissions (read, write, execute) for the user or group.

Conclusion

As you step into the Linux wonderland, remember that file permissions are like magical guardians keeping your treasures safe. Playing with permissions is like crafting your secret code. And when things get exciting, Access Control Lists step in like your trusty sidekicks ๐ŸŒˆ๐ŸŒ 

So, whether you're a computer whiz or just starting your journey, understanding file permissions and Access Control Lists is like having a magical key to unlock the secrets of Linux. Now you're ready to explore, learn, and protect your digital treasures! ๐Ÿ—๏ธ๐ŸŽ‰

ย