If you have ever tried running a script or saving a file in Linux and seen a "Permission denied" message, you have already met Linux's built-in security guard. Understanding Linux File Permissions helps you keep your files safe while letting the right programs do their job.

The Apartment Building Analogy

Think of every file in Linux like an apartment with three types of people who might knock on the door:

  • Owner (User - u): You, the person who owns the apartment.
  • Group (g): Your roommates or teammates who share access.
  • Others (o): Everyone else on the street.

Viewing Permissions with ls -l

To check who can do what to a file, open your terminal and run ls -l (long listing):

# List files with their permission details
ls -l script.sh

# Example output:
# -rwxr-xr-- 1 bagus staff 1234 Dec 2 09:00 script.sh

Look at the first 10 characters: -rwxr-xr--. Ignore the very first dash (- means it is a regular file). The remaining 9 letters are split into three groups of three: rwx (Owner), r-x (Group), and r-- (Others).

  • r (Read): Can open and view the file.
  • w (Write): Can edit or delete the file.
  • x (Execute): Can run the file as a program or script.

Changing Permissions Safely with chmod

Linux uses simple numbers for each permission letter: Read = 4, Write = 2, and Execute = 1. You just add them together for each group:

  • 7 (4 + 2 + 1) = Read, Write, and Execute (full access)
  • 5 (4 + 0 + 1) = Read and Execute (safe for teammates/web server)
  • 4 (4 + 0 + 0) = Read only
# Give owner full access (7), and group/others read+execute (5)
chmod 755 script.sh

# Give owner read+write (6), and everyone else read-only (4)
chmod 644 notes.txt

3 Things to Remember

  • Three audiences: Every file separates permissions for Owner, Group, and Others.
  • Three actions: r (4) = read, w (2) = write, x (1) = execute.
  • Common presets: Use chmod 644 for normal text files and chmod 755 for scripts you want to run.