Day 4: Mastering Linux File Permissions with Essential Flags ๐Ÿš€

Day 4: Mastering Linux File Permissions with Essential Flags ๐Ÿš€

ยท

3 min read

Welcome back to the day 4th of DevOps90Challenge! In today's installment, we're diving deeper into Linux file permissions, exploring essential flags that empower DevOps engineers to manage access rights effectively and ensure system security.

When you type in ls -l (listing all files in current directory with details) you usually see something like this:

Today, we will focus on the first column, which is the file permissions.

Understanding Linux File Permissions:

In Linux, each file and directory is associated with three sets of permissions:

  1. Owner Permissions: Pertaining to the user who owns the file/directory.

  2. Group Permissions: Pertaining to the group associated with the file/directory.

  3. Others Permissions: Pertaining to all other users.

These permissions can be represented using three characters: r for read, w for write, and x for execute.

The permissions of read, write, execute also have numeric values.

Linux file permissions can be represented both in binary and octal formats:

  • Binary Representation:

    • Read (r) = 1

    • Write (w) = 1

    • Execute (x) = 1

Each permission is represented by a bit: read (r) = 4, write (w) = 2, execute (x) = 1.

For example:

  • rwx = 111 in binary, granting all permissions.

  • rw- = 110 in binary, denying execute permission.

  • Octal Representation:

    • Each group of permissions (owner, group, others) is represented by a 3-digit octal number.

    • Read (r) = 4

    • Write (w) = 2

    • Execute (x) = 1

For example:

  • rwx = 111 in binary = 7 in octal, granting all permissions.

  • rw- = 110 in binary = 6 in octal, denying execute permission.

How to use chmod???

Now lets find how we can set permissions to any file or directory in linux system with chmod command with some cool flags.

chmod u+x file

1.Explanation: Adds execute permission for the owner of the file named 'file'.

chmod g-w file

2.Explanation: Removes write permission for the group of the file named 'file'.

chmod u=rw,g=r,o=r file

3.Explanation: Sets permissions explicitly for owner, group, and others of the file named 'file'.

chmod -R +x directory

4.Explanation: Recursively adds execute permission to all files and directories within the directory named 'directory'.

chmod -v 644 file.txt

5.Explanation: Changes permissions of the file 'file.txt' to 644, showing verbose output.

chmod -f 600 private_file.txt

6.Explanation: Changes permissions of the file 'private_file.txt' to 600, suppressing error messages.

chmod a=rwx file.txt

7.Explanation: Sets permissions of the file 'file.txt' to rwxrwxrwx, granting full access to all users.

chmod u+s file

8.Explanation: Sets the setuid bit for the file 'file', allowing it to be executed with the permissions of the owner.

chmod g+s directory

9.Explanation: Sets the setgid bit for the directory 'directory', making files created within it inherit the group of the directory.

These commands, when executed in a terminal, will modify file permissions accordingly.

In short, mastering chmod and Linux file permissions is crucial for DevOps success. Through this leg of the DevOps90Challenge, we've learned how to control access and enhance security. Let's keep learning and growing together, embracing each challenge with enthusiasm. Stay tuned for more adventures in the world of DevOps! ๐Ÿš€๐Ÿ’ป #DevOps90DayChallenge #LinuxPermissions ๐ŸŒŸ๐Ÿ” #HappyLearning๐Ÿš€

ย