Chapter 5

File Permissions

Linux controls who can read, write, or execute files using permissions for the owner, group, and others.

Reading permissions

Use ls -l to see permissions. Example:

Terminal
-rw-r--r-- 1 user group 1234 Mar  7 10:00 myfile.txt
drwxr-xr-x 2 user group 4096 Mar  7 10:00 mydir

The first column shows type and permissions: r = read, w = write, x = execute. The three groups are owner, group, and others.

Changing permissions with chmod

Use chmod to change permissions. Numeric form: read=4, write=2, execute=1. Example:

Terminal
chmod 644 myfile.txt   # owner rw, others read-only
chmod 755 mydir        # owner full, others read+execute

Changing ownership

Use chown to change owner and optionally group:

Terminal
sudo chown user:group myfile.txt