Blog Datasheets Home About me Clients My work Services Contact

G2Labs Grzegorz Grzęda

Linux 'chmod' command

June 2, 2024

Understanding and Using the Linux ‘chmod’ Command

When working on a Linux system, permissions play a vital role in maintaining the security and control of files and directories. The chmod command is a powerful tool that enables users to modify and manage these permissions. In this blog post, we will explore what permissions are, the symbolic and octal notation used by chmod, and provide examples of common scenarios.

What are Permissions?

In Linux, each file and directory has three sets of permissions: user, group, and others. The permissions determine the level of access each entity has to the file or directory. The three types of access are: read (r), write (w), and execute (x). Here’s a breakdown of each permission type:

Symbolic Notation

Symbolic notation allows us to modify permissions in an intuitive and readable way. It consists of three parts: who we want to modify, what permissions we want to change, and the operation to perform (+, -, =). The syntax is as follows:

1
chmod [who][operation][permission] [file/directory]

The “who” portion specifies who we want to modify:

The “operation” portion defines what action we want to take:

Finally, we specify the permission(s) we want to modify: r, w, or x.

Examples of Symbolic Notation:

  1. Grant read and write permissions to the user:

    1
    
    chmod u+rw file.txt
    
  2. Remove read and execute permissions for the group:

    1
    
    chmod g-rx file.txt
    
  3. Set execute permission for others:

    1
    
    chmod o=x file.txt
    

Octal Notation

While symbolic notation is more human-readable, octal (numeric) notation is commonly used in scripts and for bulk changes. Each permission type receives a numeric value:

To modify permissions using octal notation, we need to calculate the sum of the numerical values for each permission type. Here’s the basic syntax:

1
chmod [numeric-value] [file/directory]

Examples of Octal Notation:

  1. Grant read, write, and execute permissions to the user:

    1
    
    chmod 700 file.txt
    
  2. Remove read and write permissions for the group and others:

    1
    
    chmod 600 file.txt
    
  3. Set read and execute permission for the user, read permission for the group and others:

    1
    
    chmod 544 file.txt
    

Conclusion

The chmod command is a crucial tool for managing permissions on Linux systems. Understanding and using it correctly is vital for maintaining security and controlling access to files and directories. Whether using symbolic or octal notation, remember to consider the implications of the changes you make. With this knowledge, you can confidently manage permissions and ensure the integrity of your system.


➡️ Time-Sensitive Networking (TSN) on ESP32: Achieving Deterministic Behavior


⬅️ Secure Communication with ESP32: Implementing TLS/SSL


Go back to Posts.