Linux – File Ownership and Permissions

Akkkk. Linux file permissions drive me crazy. Yes they are completely necessary (or so I am told) but I feel like I fight with them all the time.

Here is my cheat sheet for viewing and changing permissions:

View Owner and Permissions

ls -l or ls -l filename

It shows the permission settings, grouped in a string of characters (-, r, w, x) classified into four sections:

  1. File type. There are three possibilities for the type. It can either be a regular file (), a directory (d) or a link (i).
  2. File permission of the user (owner)
  3. File permission of the owner’s group
  4. File permission of other users

Change ownership

file permission syntax explained
Graphic from https://phoenixnap.com/kb/linux-file-permissions

chown [OPTIONS] USER[:GROUP] FILE(s)

The following example will change the ownership of all files and subdirectories:

chown -R user:group /file/path/

-R means recursive

Change permissions

In symbolic notation, we provide chmod with a comma-separated string using references for user (u), group (g) and others (o).

We can set these same permissions with the symbolic notation:

chmod u=rwx,g=rw,o=r <document.docx>

the privledges you can give are r, w, and x, for read, write, and execute

What about these numbers? basically the same thing – you can do:

chmod 764 filename

Where each of the three numbers above are User Owner Group permissions – equivalent to the chmod u=rwx,g=rw,o=r example above

With the numbers:
7 = read, write, and execute

6 = read and write

= read and execute

= read only

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.