Permissions
Every file and directory on Linux has an owner, a group, and a set of permissions controlling who can read, write, or execute it.
ls -l notes.txt
# -rw-r--r-- 1 ada staff 128 Jan 5 10:00 notes.txt
That first cryptic-looking column breaks down into four parts:
- rw- r-- r--
β β β β
β β β ββ others: read only
β β βββββββ group: read only
β ββββββββββββ owner (ada): read and write
ββββββββββββββββ file type (- = regular file, d = directory)
Each group of three letters means read, write, execute, in that fixed order, a - means that permission is absent.
Changing permissions
chmod +x deploy.sh # add execute permission for everyone
chmod u+w notes.txt # add write, but only for the (u)ser/owner
chmod 644 notes.txt # numeric form: owner rw-, group r--, others r--
The numeric form adds up read (4) + write (2) + execute (1) per group: 6 = rw-, 7 = rwx, 4 = r--. 644 is an extremely common default for regular files, 755 for scripts and directories (execute lets you cd into a directory, not just list it).
Changing ownership
sudo chown ada:staff notes.txt # change owner (ada) and group (staff)
Changing ownership requires root, since it's a security-sensitive operation, you can't just hand your files off to someone else's ownership without a privileged account authorizing it.