# The Power Trio: Chmod, Chown, and ACL for Linux File Management"

In the Linux system, we can assign different permissions to different files and directories using the **chmod** command and change the ownership of a file using the **chown** command while **ACL** was created so that regular users could share their files and directories with certain specific users and groups.

`chmod`, which stands for "change mode," is a command used to modify file permissions in Linux. File permissions determine who can read, write, or execute a file or directory. The basic syntax of `chmod` is as follows:

```bash
chmod permissions filename
```

There are different permissions like read**(r)**, write**(w)** and execute**(x)**. The permission can be represented in octal numbers or in symbolic representation. Here Read is assigned 4, 2 for write, and 1 for execute. For example, for a file full permission can be represented with **777** value or **rwxrwxrwx** value. It shows that the owner, group, and other users have full permission i.e. read, write, and execute the particular file. Let's understand from the practical.

Let's create a directory and a text file named **"demo"** and see the default permission in the file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694757319998/e7feecc6-34c5-48c6-8647-b43cf6f70d83.png align="center")

We can see in the above screenshot permission for demo directory is drwxrwxr-x i.e. 775 and for the demo text file is -rw-rw-r-- i.e. 644

Let's change the permission on each and see the changes.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694757879462/512ae52e-ac13-4578-a7d2-2803cc712447.png align="center")

We changed the permission for the demo directory to **"644"** which means the owner has read+write permission, group and others have only read permission. In another command, we changed the permission of the demo.txt file, in addition to previous permissions, the owner(o) has added execute(x) permission, no change for the group though we gave g+r it is already available previously and other has added write and execute permission. In this way, we can symbolically assign permission to any file.

### chown

The `chown` command, short for "change owner," is used to change the ownership of files and directories in Linux. Ownership includes the user and group associated with a file or directory. The basic syntax for `chown` is:

```bash
chown owner:group filename
```

Let's change the ownership of demo.txt practically.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694759013113/d8187720-30f9-41d5-9181-72ef9ffe2273.png align="center")

Previously the owner and group assigned for demo.txt were **subash: subash.** But now the owner and group assigned are **user1** and **user1.** Here you can see a regular user can't change that ownership, only the root user has permission.

## **Access Control with ACL**

While `chmod` and `chown` provide robust basic file permission and ownership control, there are situations where you need more fine-grained access control. This is where Access Control Lists (ACLs) come into play. ACLs allow you to set permissions for multiple users and groups on a single file or directory.

To add an ACL to a file or directory, you can use the `setfacl` command:

```bash
setfacl -m u:user:permissions,g:group:permissions,o:other:permissions filename
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1694760122631/3b94f7a9-357e-4d56-bfe4-e6aaaccb8551.png align="center")

Using getfacl, we can view all the details of a file i.e. owner, group, and permissions. Using setfacl we assigned the different permissions and the differences can be viewed in the above output file.

## **Practical Use Cases**

Now that we understand the basics of `chmod`, `chown`, and ACL, let's explore some practical use cases where these commands shine:

1. **Securing Sensitive Files**: We can use `chmod` and ACL to restrict access to sensitive data files.
    
2. **Collaborative Development**: When working on group projects, `chown` and ACL helps manage file ownership and permissions among team members.
    
3. **Multi-User Systems**: On multi-user systems, `chmod`, `chown`, and ACL plays a vital role in maintaining data privacy and security.
    
4. **Managing Web Servers**: When running web servers like Apache or Nginx, you can use these commands to control file permissions for web applications.
    

Happy Learning!!
