← Linux Fundamentals

Lesson 6 of 7

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.

πŸ“ Permissions Quiz

Passing score: 70%
  1. 1.In "-rw-r--r--", what permissions does the file's owner have?

  2. 2.The numeric permission 644 grants the owner read+write, and group/others read-only.

  3. 3.The command to add execute permission to a script for everyone is: chmod ____ deploy.sh