Basics of file permissions

On a linux system

ยท

2 min read

๐Ÿ”’ Mastering File Permissions in Linux with chmod ๐Ÿ› ๏ธ

Hello Hashnode community! ๐Ÿ‘‹ Today, let's dive deep into the world of file permissions in Linux, unraveling the mysteries behind the chmod command. Whether you're a seasoned sysadmin or just stepping into the realm of Linux, understanding how to wield chmod effectively is crucial.

NOTE: chmod command requires root access or needs the file user owner to execute the command

1. Symbolic Method:

Linux permissions, like a secret language, use symbols to convey who gets access to what. Let's break down the symbolic method:

  • User (u), Group (g), Other (o):

    • r - Read
    • w - Write
    • x - Execute
  • Operators:

    • + - Add permission
    • - - Remove permission
    • = - Set permission explicitly
  • Examples:

    • Grant read and write permissions to the user:

      chmod u+rw filename
      
    • Remove execute permission for the group:

      chmod g-x filename
      
    • Set execute permission for others:

      chmod o=x filename
      
    • Combine permissions with explicit setting:

      chmod u=rw,g=x filename
      
    • Combine permissions for the user and group:

      chmod ug+x filename
      

2. Numerical Method:

Now, let's talk numbers. The numerical method uses octal representation:

  • Octal Representation:

    • 4 - Read
    • 2 - Write
    • 1 - Execute
  • Examples:

    • Grant read and write permissions to the user, read-only to the group:

      chmod 644 filename
      
    • Full control to the owner, read and execute to the group, no permissions to others:

      chmod 700 filename
      
    • Read, write, and execute to the user, read and execute to the group, no permissions to others:

      chmod 711 filename
      

3. Recursive Permission Setting:

For the power users managing directories and their contents:

  • Apply permissions recursively:
    chmod -R u+rw,go+r my_directory
    

Understanding both symbolic and numerical methods is your ticket to mastering file permissions in Linux. Whether you prefer the expressive language of symbols or the succinct octal representation, chmod empowers you to secure your files and directories with precision.

So go ahead, command your permissions, and let your Linux system dance to your tune! ๐Ÿ’ƒ๐Ÿง

ย