Altering Permissions

Once you understand how permissions work, you'll need to know how to change them. Linux provides the chmod and chown commands for this.

1. chmod (Change Mode)

There are two ways to use chmod: the Symbolic method and the Numeric method.

Numeric Method (Most Common)

You provide a 3-digit number, where each digit represents the sum of the permissions (Read=4, Write=2, Execute=1).

Bash

# Give the owner full permissions, and everyone else read-only
chmod 744 script.sh

# Give everyone full permissions (not recommended for security!)
chmod 777 public_file.txt

Symbolic Method

Use letters (u for User, g for Group, o for Others, a for All) and symbols (+ to add, - to remove).

Bash

# Add execute permission for the owner
chmod u+x script.sh

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

2. chown (Change Owner)

The chown command changes which user or group owns a file. You usually need sudo (admin privileges) to use this.

Bash

# Change the owner of a file to 'john'
sudo chown john report.pdf