DEV Community

Kervie Sazon
Kervie Sazon

Posted on

Linux Fundamentals - Part 13: File Permissions & Ownership

File Permissions

In Linux, every file and folder beongs to:

  • Who can read it
  • Who can modify it
  • Who can run it

These rules help keep the system secure.

Every File Has an Owner

In linux, every file and folder belongs to:

  1. User (Owner) – The person who created the file
  2. Group – A collection of users
  3. Others – Everyone else on the system

Used this command to check:

ls -l
Enter fullscreen mode Exit fullscreen mode

Example output:

-rw-r--r-- 1 kerviejay sysad 1200 Feb 15 notes.txt
Enter fullscreen mode Exit fullscreen mode

Focus on this part:

kerviejay sysad
Enter fullscreen mode Exit fullscreen mode

This means:

  • keviejay = file owner
  • learnlinux = group owner

Understanding Permission Symbols

I learn how to read this:

--rw-r--r--
Enter fullscreen mode Exit fullscreen mode

It's divided into three parts:

rw-   r--    r--
|     |      |
User  Group  Others
Enter fullscreen mode Exit fullscreen mode

Each set has 3 letters:

Letter Meaning
r Read
w Write
x Execute (run as program)
- No permission

So:

rw- - Owner can read and write
r-- - Group can only read
r-- - Others can only read

What chmod 755 Actually Means

Each permission has a number:

Permission Value
r 4
w 2
x 1

Just add them.
Example:
7 = 4 + 2 + 1 = rwx
6 = 4 + 2 = rw-
5 = 4 + 1 = r-x

So when I run:

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

It means:

  • Owner - 7 → rwx
  • Group - 5 → r-x
  • Others - 5 → r-x

Changing Permissions

  1. Using Numbers
chmod 644 file.txt
chmod 755 script.sh
chmod 600 private.txt
Enter fullscreen mode Exit fullscreen mode

Common examples:
644 - Normal file
755 - Executable scrip
600 - Private file (like SSH keys)

  1. Using Letters
chmod u+x script.sh
Enter fullscreen mode Exit fullscreen mode

This means:
u - user
+x - add execute permission

Other options:
g - group
o - others
a - all

Example:

chmod a+r file.txt
Enter fullscreen mode Exit fullscreen mode

Means: Adds read permission for everyone.

Changing File Owner

Sometimes you need to change who owns a file.

sudo chown newuser file.txt
Enter fullscreen mode Exit fullscreen mode

Change owner and group:

sudo chown newuser:newgroup file.txt 
Enter fullscreen mode Exit fullscreen mode

Change group only:

sudo chown :newgroup file.txt
or 
sudo chgrp newgroup file.txt
Enter fullscreen mode Exit fullscreen mode

Today’s lesson helped me move from memorizing commands to actually understanding how Linux permissions work. I learned how Linux file permissions and ownership work, including the difference between user, group, and others. I now understand how to read permission symbols like rwx and how numbers like 755 and 644 are calculated using chmod.
Tomorrow, I will be moving on to Archiving and Compressing files as Part 14 of my learning journey.

Top comments (0)