beginner 10 minutes

Understanding Linux File Permissions

Learn how Linux file permissions work — read, write, execute, chmod, chown, and why you get 'Permission denied'.

Prerequisites

  • Basic terminal knowledge
1

Why 'Permission denied' happens

Linux controls who can read, write, and run every file. When you see "Permission denied", it means your user account doesn't have the right permission for that action. This is a security feature — it keeps you from accidentally breaking your system and stops malware from modifying system files.

2

Read permission letters

List a file's permissions with ls -l. You'll see something like -rwxr-xr--. Here's how to read it:

  • Position 1: file type (- = file, d = directory)
  • Positions 2-4: owner permissions (rwx)
  • Positions 5-7: group permissions (r-x)
  • Positions 8-10: others permissions (r--)

Each position is: r = read, w = write, x = execute, - = no permission.

ls -l myfile.txt
# Output: -rw-r--r-- 1 gabriel users 1024 Mar 5 10:00 myfile.txt
# Owner: read+write | Group: read | Others: read
3

Change permissions with chmod

Use chmod to add or remove permissions. The + adds a permission, - removes it. Use u (owner), g (group), o (others), or a (all).

# Make a file executable:
chmod +x script.sh

# Remove write permission for others:
chmod o-w myfile.txt

# Give owner full access, read-only for everyone else:
chmod u=rwx,go=r myfile.txt
4

Numeric (octal) permissions

You'll often see permissions written as numbers like 755 or 644. Each digit is a sum: r=4, w=2, x=1.

  • 7 = rwx (4+2+1)
  • 6 = rw- (4+2)
  • 5 = r-x (4+1)
  • 4 = r-- (4)

Common combos: 755 = owner full, others read+execute. 644 = owner read+write, others read-only.

# Set 755 permissions:
chmod 755 script.sh

# Set 644 permissions:
chmod 644 document.txt
5

Change file ownership with chown

Each file has an owner and a group. Use chown to change them. You need sudo for this.

# Change owner:
sudo chown gabriel myfile.txt

# Change owner and group:
sudo chown gabriel:users myfile.txt

# Change ownership of a folder and everything inside:
sudo chown -R gabriel:users /path/to/folder/
6

When to use sudo vs changing permissions

  • Use sudo for one-time system tasks (installing software, editing system config)
  • Use chmod/chown when you need to permanently fix who can access a file
  • Never run everything as root or chmod 777 everything — that defeats the entire security model

Avoid chmod 777 — it gives everyone full access. If you think you need 777, you probably need to change the file owner instead.

On this page