Linux Permissions

May 03, 2017

Length: 09:58

Permissions are confusing, and it's hard to find proper information on them (no need to chmod 0777 anything). We'll cover how all of this works.

Ownership

We have three "actors" that can perform operations on a file or directory:

  • users
  • groups
  • other

Files (including symlinks and unix sockets), directories, and proceses all have an assigned user and group.

Permissions

Users, groups, and anyone else ("other") have specific things they can do to a file or directory. These are the three permissions a user/group/other can do on a file/directory:

  • read (r)
  • write (w)
  • execute (x)

Files:

  • Read is the ability to read the contents of a file, including open in an editor in a read-only format
  • Write is the ability to modify or delete a file
  • Execute is the ability to run the file as a program (e.g. a shell script, python script, php script)

Directories:

  • Read is the ability to investigate a directory (ls -lah)
  • Write is the ability to add to a directory, or delete the directory
  • Execute is the ability to cd into directory

  • -rwx-rw-r-- - A file. U: rwx, G: rw, O: r

  • drwx-rwx-r-x - A directory. U: rwx, G rwx, O: rx

Changing Ownership / Permissions

We can change ownership of files:

  • chown [-R] user /path
  • chown [-R] user:group /path
  • chown [-R] user: /path

The -R flag is to change files recursively. There is also the chgrp command to change the group of a file/directory.

We can change permissions of a file/directory with chmod:

  • chmod [-R] u=rwx,g=rw,o=r /path
  • chmod [-R] u+x,g+wx,o-w /path