Tech

Linux File Permissions

Published
Published:
Table of Contents

On Linux, every file and folder decides who is allowed to read it, change it, or run it. This is the permissions system. It looks confusing at first because of numbers like 755, but the idea behind it is quite neat.

Three actions, three groups of people

There are three things you can do to a file:

  • read (r) — look at it
  • write (w) — change it
  • execute (x) — run it as a program

And three groups these apply to:

  • owner — the person who made it
  • group — a set of users
  • others — everyone else

So permissions answer a simple question: for each group of people, what are they allowed to do?

Reading the output of ls -l

-rwxr-xr-x  1 shravan staff  1024 main.sh

That rwxr-xr-x is three blocks of three:

  • rwx for the owner — read, write, execute
  • r-x for the group — read and execute, no write
  • r-x for others — same

A dash means “not allowed”.

Where the numbers come from

Each permission has a value: read = 4, write = 2, execute = 1. Add them up for each group:

  • 7 = 4 + 2 + 1 = read, write, execute
  • 5 = 4 + 0 + 1 = read, execute
  • 0 = nothing

So 755 means owner gets everything, group and others get read and execute. That is why you see chmod 755 so often:

chmod 755 main.sh

A safety note

Please do not fix every problem with chmod 777. That means “everyone can do everything”, which is the digital version of leaving your front door wide open. Give only the permissions actually needed.

Support this post Sponsor