Permissions Overview

UNIX and Linux rely on a simple and consistent permission system to control access to files and directories. Understanding it is essential for safely managing files and running commands.

Basic Permission Model

Each file or directory has three types of permissions fore three categories of users.

permissionmeaning
rRead - View the file contents or list a directory
wWrite - Modify the file or add/remove files into a directory
xExecute - run the file as a program or enter a directory
user categoriesmeaning
uOwner (the user who created the file)
gGroup (a set of users)
oOthers (everyone else)

There are more special permissions however we will not be covering that.

Example from ls -l: -rw-r--r-- 1 alice staff 27 Mar 2 18:52 example.txt Breakdown:

shellsession
user@machine:~$ ls -l example.txt
-rw-r--r-- 1 user user     27 Mar  2 18:52 example.txt

Changing permissions

chmod - Change Model

chmod [options] <permissions> <file>

Numeric mode:

shellsession
user@machine:~$ chmod 755 script.sh

Symbolic mode:

shellsession
user@machine:~$ chmod u+x script.sh # add execute to owner
user@machine:~$ chmod g-w script.sh # remove write from group
user@machine:~$ chmod o=r script.sh # set others to read only

chown - change ownership chown owner:group filename

shellsession
user@machine:~$ chown alice:staff example.txt

Only root (or sudo) can change ownership.

Summary

Every file/directory has owner, group, others and read/write/execute permissions.

Use ls -l to inspect.

Use chmod to modify permissions, chown to change ownership.

Directories need execute to enter; read to list; write+execute to modify contents.

Special bits are advanced, but you may see them in shared directories like /tmp.