---
title: "Master Linux Permissions: A Deep Dive into Chmod and Chown"
description: "Dive deep into this ATA Learning tutorial on the chmod and chown commands. Get started mastering Linux permissions today!"
canonical: "https://adamtheautomator.com/chmod-and-chown/"
---

# Master Linux Permissions: A Deep Dive into Chmod and Chown

> Dive deep into this ATA Learning tutorial on the chmod and chown commands. Get started mastering Linux permissions today!

Source: https://adamtheautomator.com/chmod-and-chown/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Master Linux Permissions: A Deep Dive into Chmod and Chown](https://adamtheautomator.com/wp-content/uploads/2023/10/Chmod-and-Chown.jpg)

# Master Linux Permissions: A Deep Dive into Chmod and Chown

[![](https://secure.gravatar.com/avatar/b1faae2f957a0d43de36dfd25e8c08537718fb87c49cfd0a15b0e860a7f7b9a0?s=192&d=mm&r=g)Mercy Bassey](https://adamtheautomator.com/author/mercy-bassey/)31 October 202311 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Grasping the chmod and chown Commands](#grasping-the-chmod-and-chown-commands)
*   [Listing Files and Viewing Permissions](#listing-files-and-viewing-permissions)
*   [Modifying Permissions via the chmod Command: Symbolic Mode](#modifying-permissions-via-the-chmod-command-symbolic-mode)
*   [Adjusting Access Rights Using the chmod Command: Octal Mode](#adjusting-access-rights-using-the-chmod-command-octal-mode)
*   [Changing File Ownership with the chown Command](#changing-file-ownership-with-the-chown-command)
*   [Enforcing the chown Command to Modify Group Ownership](#enforcing-the-chown-command-to-modify-group-ownership)
*   [Altering File Ownership via Numeric UID and GID](#altering-file-ownership-via-numeric-uid-and-gid)
*   [Conclusion](#conclusion)

Have you ever found yourself tangled in the perplexing world of Linux permissions? If you still wonder who gets to read, write, or execute what, well, you are in the right place. Demystify the intricate art of Linux permissions, focusing specifically on the powerhouse duo: `chmod` and `chown`!

In this tutorial, you will equip yourself with the skills to control access to your files and directories confidently.

Now roll up those sleeves and conquer Linux permissions like a champ!

## Prerequisites

Before you embark on this deep dive into Linux permissions, ensure you have A Linux Machine for mastering the `chmod` and `chown` commands. This tutorial uses Ubuntu 22.04 LTS (Jammy Jellyfish).

## Grasping the `chmod` and `chown` Commands

In the realm of Linux permissions, the `chmod` and `chown` commands wield significant power. Understanding how to use these commands effectively is crucial for any Linux user, from beginners to seasoned administrators.

Both commands offer many ways of controlling your Linux system, but below are the basics of what each is capable of:

*   `chmod` – This command is the key to managing file and directory permissions in Linux, which allows you to specify who can read, write, and execute a file. By employing a combination of symbols and numeric codes, you can grant or restrict access to users, groups, and others.
*   `chown` – With this command, you can change the ownership of files and directories. This command is invaluable when you need to transfer administrative control or alter the association between a file and a user/group.

Whether safeguarding sensitive data or streamlining access for a team, these commands are your trusty companions in the world of Linux file operations.

Read on and dive even deeper into the intricacies of these commands.

## Listing Files and Viewing Permissions

Before changing permissions and ownership with the `chmod` and `chown` commands, the first step is to list files and view their permissions.

Like finding a book in a library, in Linux, you will often need to view a list of files along with their associated permissions. This knowledge is crucial for effective file management.

Related:[Linux Directory Commands : A Complete Guide](https://adamtheautomator.com/linux-directory-commands/)

To view the permissions of a file or directory:

Open a terminal and execute the following `ls` command to list all files and directories in the current working directory in a long format (`-l`)

```bash
ls -l
```

The long format provides detailed information about each file or directory, as shown below.

This information includes permissions, number of links, owner, group, size, and modification time. But your focus right now is on the file permissions.

![Viewing a list of files and directories](https://adamtheautomator.com/wp-content/uploads/2023/10/image-138.png)

Viewing a list of files and directories

Three key permissions govern every file and directory: read (r), write (w), and execute (x). Each dictates how users interact with the content of every file and directory.

In addition, each of these permissions is applied across three distinct categories of ownership: owner, group, and others (users who are neither nor members of the group).

The following illustrates each part of file permissions:

*   The first character indicates a file (**–**) or a directory (**d**).
*   The first part (**rw-)** – Provides the owner read and write permissions but not execute.
*   The second part (**rw-**) – Grants group read and write permissions but not execute.
*   The last part (**r–**) – Allows others permission to read but not write or execute.

![Illustrating file permissions](https://adamtheautomator.com/wp-content/uploads/2023/10/image-139.png)

Illustrating file permissions

## Modifying Permissions via the `chmod` Command: Symbolic Mode

Expanding your grasp of file permissions, dive into a powerful tool for modifying permissions. Imagine adjusting who can access, modify, or execute a file or directory with precision. The `chmod` command (change mode) grants you the power to take control of your Linux system.

When you need a flexible and expressive way to control access to your files and directories precisely, the symbolic mode will do the trick.

To modify permissions with the `chmod` command via the symbolic mode, follow these steps:

1\. Execute the below `who` command to create a new file (`>`) called `user.txt` as a non-privileged user, containing a list of currently logged-in users on your Linux machine.

This command does not provide output on the terminal, but you will verify the file’s permissions in the following step.

```bash
who > user.txt
```

Related:[whoami: A Comprehensive Guide to OS User Identification](https://adamtheautomator.com/whoami/)

2\. Next, run the command below to view the permissions for the _`user.txt`_ file.

```bash
ls -l user.txt
```

Below, you can see the file’s default permissions, the owner, the day and month of creation, and the file name.

Take note of the current file permission, as you will later make a comparison. Your focus for now is the user permissions (**rw-**).

![Viewing the file’s default permissions](https://adamtheautomator.com/wp-content/uploads/2023/10/image-145.png)

Viewing the file’s default permissions

3\. Now, run the following command to remove (`-`) the write (`w`) permission for the owner (`u`), leaving every other permission for other categories unchanged.

The following table breaks down what each symbol represents:

| User Symbol | Details | Operation Symbol | Details | Permission Symbol | Details |
| --- | --- | --- | --- | --- | --- |
| u | Owner | + | Add permissions | r | Read |
| g | Group | – | Remove permissions | w | Write |
| o | Others | \= | Set permissions explicitly | x | Execute |

When successful, the `chmod` command has no output on the terminal, which applies throughout this tutorial.

```bash
chmod u-w user.txt
```

4\. After changing permissions, run the below command to view the `user.txt` file’s permissions.

```bash
ls -l user.txt
```

Compare the file permissions you noted in step two (**rw-**) with the one below. Notice that the owner (u) now only has the read permission (**r–**).

![Viewing modified owner permission](https://adamtheautomator.com/wp-content/uploads/2023/10/image-144.png)

Viewing modified owner permission

5\. Now, execute each command below to perform the following:

*   Add (`+`), write (`w`), and execute (`x`) permissions for the owner (`u`) on the same `user.txt` file.
*   View the `user.txt` file’s information to verify the modified permissions.

```bash
chmod u+wx user.txt
ls -l user.txt
```

As shown below, the user now has read, write, and execute permissions (**rwx**) for the _user.txt_ file.

![Viewing modified owner permissions](https://adamtheautomator.com/wp-content/uploads/2023/10/image-143.png)

Viewing modified owner permissions

6\. Instead of adding, run the `chmod` command below to remove (`-`) the following:

*   Execute (`x`) permission for the owner (`u`).
*   Write (`w`) permission for the group (`g`).
*   All permissions (`rwx`) for others (`o`).

This command lets you remove permissions from different categories simultaneously with a single command.

This time, the `-v` option tells `chmod` to display a message about the changes made by the operation.

```bash
chmod -v u-x,g+w,o-rwx user.txt
```

![Viewing modified permissions for owner, group, and others](https://adamtheautomator.com/wp-content/uploads/2023/10/image-142.png)

Viewing modified permissions for owner, group, and others

7\. Next, run the following command to perform the following operations:

*   Add (`+`) read permissions (`r`) to all categories.
*   Remove (`-`) write and execute permissions (`wx`) for all (`a`) categories.

```bash
chmod a+r,a-wx user.txt
```

8\. Now, execute the below command to view the `user.txt` file’s updated permissions.

```bash
ls -l user.txt
```

![Viewing updated permissions for all categories](https://adamtheautomator.com/wp-content/uploads/2023/10/image-141.png)

Viewing updated permissions for all categories

> _💡 Alternatively, you can modify the same permission for all three categories (user, group, and others) with the following commands:_
> 
> _`chmod ugo-r` – Removes (`-`) read permissions (`r`) for all three categories (`ugo`)._
> 
> _`chmod ugo+r` – Adds (`+`) read permissions (`r`) for all three categories (`ugo`)._

9\. Lastly, run the commands below to perform the following:

*   `chmod` – Set (`=`) read and write (`rw`) permissions for the owner and group, and remove permissions of others (`o=`).  
    The `=` symbol lets you explicitly set permissions and override any existing permissions. If no permissions are specified after the `=` symbol, all permissions for that category are removed.
*   `ls` – View the changes you made to the `user.txt` file’s permissions.

```bash
chmod ug=rw,o= user.txt
ls -l user.txt
```

![Viewing the modified permissions set](https://adamtheautomator.com/wp-content/uploads/2023/10/image-140.png)

Viewing the modified permissions set

## Adjusting Access Rights Using the `chmod` Command: Octal Mode

Imagine having the ability to swiftly and precisely set permissions for your files without the complexities of symbolic notation. Octal mode (base eight notation) will become your new favorite method for managing permissions.

In octal mode (base eight notation), permissions are represented using a four or three-digit number, from 0 to 7. Each number corresponds to a specific set of permissions for the owner, group, and others, as follows:

*   Read (r) = 4
*   Write (w) = 2
*   Execute (x) = 1
*   No permissions (-) = 0

To see how octal mode works in managing file permissions, carry out these steps:

1\. Execute the below `chmod` command to add the following permissions (`664`) to the `user.txt` file:

*   Owner – read (`4`) + write (`2`) + execute (`0`) = `6`
*   Group – read (`4`) + write (`2`) + execute (`0`) = `6`
*   Others – read (`4`) + write (`0`) + execute (`0`)= `4`

When using a four-digit number with the `chmod` command for file permissions in Linux, the leading digit (leftmost) represents special permissions, such as [setuid, setgid, and sticky bit](https://en.wikipedia.org/wiki/Setuid). The next three digits represent the standard permissions for the owner, group, and others, respectively.

But when using a three-digit number, the first digit represents the permissions of the file’s owner (`u`), the second for the file’s group (`g`), and the last for others (`o`).

In many cases, especially when not dealing with special permissions, you might only see three-digit notation. The leading zero, which indicates octal notation, can be implied and thus omitted. Like in the example below, instead of `0664`, you use `664`.

```bash
chmod 664 user.txt
```

2\. Next, run the below command to view the permissions for the `user.txt` file.

```bash
ls -l user.txt
```

In the output below, you can see the permissions set for the _user.txt_ file are in symbolic mode, which is equivalent to 664 in octal mode.

![Viewing permissions modified via octal mode](https://adamtheautomator.com/wp-content/uploads/2023/10/image-147.png)

Viewing permissions modified via octal mode

3\. Now, run the [`stat`](https://www.geeksforgeeks.org/stat-command-in-linux-with-examples) command below to view a comprehensive set of statistics about the _`user.txt`_ file, including the permissions in the symbolic and octal modes.

```bash
stat user.txt
```

On the **Access** property, as shown below, you will see the octal and symbolic mode associated with the file permissions of the _user.txt_ file.

With this information, you enhance your comprehension of adjusting permissions using the octal mode.

![Viewing the octal and symbolic representations of permissions](https://adamtheautomator.com/wp-content/uploads/2023/10/image-146.png)

Viewing the octal and symbolic representations of permissions

## Changing File Ownership with the `chown` Command

While permissions dictate what actions can be performed on a file or directory, you can specify who has the right to set or modify these permissions by changing the ownership.

The `chown` command (change owner) is the primary command for managing file and directory ownership. Like the `chmod` command, the `chown` command is a root-only command — only the root user can change ownership of a file or directory.

To manage ownership with the `chown` command, proceed with the steps below:

1\. Run the below commands to create a user (`useradd`) named `bill` and provide a strong password.

You need to have more than one user on your local machine other than the default user, which is you, to see how changing ownership works.

```bash
sudo useradd bill
sudo passwd bill
```

![Adding a user and updating user password ](https://adamtheautomator.com/wp-content/uploads/2023/10/image-150.png)

Adding a user and updating user password

Related:[How to Create User on Ubuntu Linux in Multiple Ways](https://adamtheautomator.com/create-user-on-ubuntu/)

2\. Next, execute each command below write a list of currently logged-in users (`who`) to a file called `new.txt` as a non-privileged user, and view (`ls`) its owner and permissions.

```bash
who > new.txt
ls -l  new.txt
```

Below, the output shows the file owner is **mercy**.

![Viewing the owner of the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-149.png)

Viewing the owner of the _new.txt_ file

3\. With the owner verified, run the `chown` command below to change the owner of the `new.txt` file to `bill`.

Like the `chmod` command, the `chown` command does not provide output, but you will verify the owner change in the following step.

```bash
sudo chown bill new.txt
```

4\. Now, run the following command to view (`ls`) the new owner of the `new.txt` file.

```bash
ls -l  new.txt
```

The output below confirms you have successfully changed the owner of the _new.txt_ file to **bill,** who now has control and authority over that file.

![Viewing the new owner of the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-148.png)

Viewing the new owner of the _new.txt_ file

## Enforcing the `chown` Command to Modify Group Ownership

In the Linux file system, every file and directory is associated not only with an individual owner but also with a group. Just as a single out-of-tune instrument can disrupt the entire ensemble, incorrect ownership can lead to potential issues.

Should you be worried? Not really. Group association allows for a layered approach to file permissions. This approach enables multiple users to collaborate and share access based on group membership.

To modify group ownership, complete the following steps:

1\. Execute the below command to view the group associated with the `new.txt` file.

```bash
ls -l  new.txt
```

![Viewing the group associated with the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-152.png)

Viewing the group associated with the _new.txt_ file

2\. Next, run the commands below, which do not provide output but perform the following:

*   Create a group (`groupadd`) called `developers`.
*   Change the group (`chown`) ownership of the `new.txt` file to `developers`.

```bash
sudo groupadd developers
sudo chown :developers new.txt
```

> _💡 Alternatively, instead of an individual approach, use the following commands to recursively change the owner and group ownership of a file or an entire directory._
> 
> _`sudo chown -R john:finance-group user.txt`_
> 
> _`sudo chown -R john:finance-group ~/Desktop`_

3\. Now, rerun the following command to view (`ls`) the new group ownership of the _`new.txt`_ file.

```bash
ls -l  new.txt
```

Below, the output confirms you have successfully changed the _new.txt_ file’s group ownership to **developers**.

![Viewing the new group ownership of the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-151.png)

Viewing the new group ownership of the _new.txt_ file

## Altering File Ownership via Numeric UID and GID

While usernames and group names offer a human-readable way to identify file owners, every user and group is also associated with unique numeric identifiers.

These unique numeric identifiers are User ID (UID) and Group ID (GID). They provide an unambiguous way to set file ownership in environments with overlapping or similar user and group names.

To change the ownership using numeric UIDs and GIDs, perform these steps:

1\. Execute the below command to list information (`ls`) about the `new.txt` file.

The `-n` option tells the `ls` command to display numeric UIDs and GIDs rather than resolving them to their corresponding user and group names.

```bash
ls -n new.txt
```

Note the UID and GID associated with the _`new.txt`_ file, as you will need them for making comparisons in the latter step.

![Viewing the UID and GID associated with the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-155.png)

Viewing the UID and GID associated with the **new.txt** file

2\. Next, run the following [`getent`](https://www.geeksforgeeks.org/getent-command-in-linux-with-examples) commands to get the UID and GID of the user and group you wish to set for your file’s ownership.

Ensure you replace `<username>` and `<groupname>` placeholders with your preferred username and group name.

```bash
getent passwd <username>
getent group <groupname>
```

Take note of the UID (i.e., **1002**) and GID (i.e., **1005**) in the following output, as you will need them for changing ownership in the next step.

By default, when a user is created in Linux, a group with the same name as the user is also created. This group serves as the user’s primary group and is automatically added to this primary group.

Thus, the GID for the user `john` differs from the GID of the `finance` group. Unless the user is explicitly added to the group, their respective GIDs remain different.

![Viewing UID and GID for user john and group finance](https://adamtheautomator.com/wp-content/uploads/2023/10/image-154.png)

Viewing UID and GID for user **john** and group _**finance**_

3\. Next, run the following command to change the `new.txt` file’s ownership and group ownership. Be sure to replace `1002` and `1005` with the ones you noted in step two.

> _💡 Note that using numeric UIDs and GIDs can be less readable than usernames and group names. Thus, ensure you are using the correct numbers to avoid unintended changes._

```bash
sudo chown 1002:1005 new.txt
```

4\. Finally, rerun the command below to list information (`ls`) about the `new.txt` file and verify the changes in the file’s ownership.

```bash
ls -n new.txt
```

Compare the UID and GID you noted in step one with the ones below. Notice that the new file ownership has been changed from **1001:1003** to **1002:1005**.

![Verifying the new UID and GID for the new.txt file](https://adamtheautomator.com/wp-content/uploads/2023/10/image-153.png)

Verifying the new UID and GID for the _**new.txt**_ file

## Conclusion

You have just embarked on a comprehensive exploration of Linux permissions, gaining mastery over crucial commands like `chmod` and `chown`. Throughout this tutorial, you have become adept at modifying permissions using symbolic and octal modes.

You have also acquired the skills to manage file ownership and group assignments, whether by name or through numeric UID and GID. With this newfound expertise in `chmod` and `chown`, you now wield powerful tools to govern access and ownership within your Linux system.

But why not further bolster your Linux proficiency? Perhaps consider delving into advanced access control methods, including [Access Control Lists (ACLs)](https://www.geeksforgeeks.org/access-control-listsacl-linux/)? Aim for even more precise control over file and directory permissions!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fchmod-and-chown%2F&text=Master%20Linux%20Permissions%3A%20A%20Deep%20Dive%20into%20Chmod%20and%20Chown)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fchmod-and-chown%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fchmod-and-chown%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
