Back to course

Basic Linux CLI II: File Permissions

Cyber Security Mastery: From Zero to Hero

Understanding File Permissions

Linux security is heavily dependent on the permission system. Use the ls -l command to view permissions.

Permission Structure Example

-rwxr-xr-- 1 user group 1024 Jan 1 10:00 filename.txt

  1. File Type: (- for file, d for directory, l for link).
  2. Permissions (9 characters): Divided into three sets of three:
    • Owner (u): rwx (Read, Write, Execute)
    • Group (g): r-x (Read, Execute)
    • Others (o): r-- (Read)

Changing Permissions (chmod)

We use chmod to change permissions, often using octal notation (r=4, w=2, x=1).

  • rwx = 4+2+1 = 7
  • r-x = 4+0+1 = 5

Example: Granting the owner full control, group read/execute, and others only read:

bash chmod 754 filename.txt

Changing Ownership (chown)

Used to change the owner or group of a file:

bash

Change owner to 'alice'

chown alice filename.txt

Change owner and group to 'alice' and 'devs'

chown alice:devs filename.txt