Understanding Linux File Permissions

·

4 min read

Hey everyone in the last blog we've seen about the basic filesystem in the linux and some basics commands in this blog we will see more about permission and ownership of the linux system

Linux file permissions are a critical part of system security, allowing administrators and users to control who can read, write, or execute files. Let’s break down how these permissions work and how to modify them.

So what is permission exactly and what we are talking about now?

For example we take our smart phones

As the owner of the phone you have full access to your mobile like you can delete the files create the files updating the system etc simply you can do whatever you want since it was your

for the scenario lets say your friend ask your phone for one 30 mins, what we will do? for security purpose we will keep passwords to our phones and the applications inside in it so that your friend doesn't change anything without your knowledge

Same thing applies here

in Linux system the owner is root

root user can do any configuration related to the system

so what about the other users? how the system admin will change the files and how they configure the things ?

Lets say your friend wants to install one application so he will ask your permission can i install it ? and you say okay it doesn't affect anything to my phone go ahead

and you give your access to install it

In linux system as the normal user you don't have access to the entire system in that cases you will use the command called sudo

sudo -> Super User Do

this command allows you to perform the action with the root access like changing the permissions to the files

CHMOD

You can change the permission of the file using the command called chmod

Breaking Down the Permission Structure

When you view a file's details using ls -l, you’ll see something like:

This line can be broken down as follows:

1. File Type

  • File Type: The first character indicates the type of file:

    • - for a regular file

    • d for a directory

    • l for a symbolic link

2. Permissions

  • Permissions: The next nine characters represent the permissions, divided into groups of three:

    • First Set (rwx): Permissions for the owner of the file.

    • Second Set (r-x): Permissions for the group that owns the file.

    • Third Set (r-x): Permissions for others (anyone else on the system).

Example Breakdown:

  • The owner has read (r), write (w), and execute (x) permissions.

  • The group and others has read (r) and execute (x) permissions.


Changing Permissions with chmod

To modify permissions, you use the chmod command, which allows changes in either symbolic or numeric mode.

Symbolic Mode

In symbolic mode, you specify:

  • Who: u (user/owner), g (group), o (others), or a (all).

  • Operation: + (add), - (remove), = (set).

  • Permission: r (read), w (write), or x (execute).

Example

Syntax

chmod <permission> <file name >

Kindly please note below the other dont have access to write and excute the file

Now im going to give write and excute permissions to the other users

for that im going to excute the command
chmod o+wx file.txt

now we will see the file below

Numeric Mode

In numeric mode, each permission is represented by a number:

  • Read (r) = 4

  • Write (w) = 2

  • Execute (x) = 1

The sum of these values represents different permission levels:

  • 7 (4+2+1) for read, write, execute

  • 6 (4+2) for read and write

  • 5 (4+1) for read and execute

  • 4 for read-only

To set permissions, use a three-digit number where:

  • The first digit is for the owner.

  • The second digit is for the group.

  • The third digit is for others.

    syntax for this mode is

    chmod <permission in numbers> <filename>

By understanding these commands and concepts, you’ll have greater control over file security and permissions on a Linux system!