How to Change File Permissions in Ubuntu Linux Terminal Using the chmod Command

Linux is built fundamentally around the concept of file security. Every single file and directory in Ubuntu has a strict set of permissions that dictate exactly who is allowed to read it, modify it, or execute it as a program. When managing a server, deploying a website, or writing bash scripts, you will frequently encounter “Permission Denied” errors. The essential tool for managing these security rules from the terminal is the chmod (change mode) command.

Understanding the Three Permission Types

Before you can change permissions, you must understand what they are. Linux defines three basic actions:

  • Read (r): The ability to open and view the contents of a file, or list the files inside a directory.
  • Write (w): The ability to modify, save, or delete a file, or create/remove files within a directory.
  • Execute (x): The ability to run a file as a script or program, or enter (cd into) a directory.

These three permissions are assigned separately to three different groups of users:

  1. User (u): The actual owner of the file.
  2. Group (g): Other users who belong to the file’s assigned user group.
  3. Others (o): Everyone else on the system (the public).

Using the Symbolic Method

The symbolic method is the most intuitive way to use chmod, as it uses letters to represent the users and permissions.

The syntax is: chmod [user][operator][permission] filename

  • Operators: Use + to add a permission, to remove a permission, and = to set exact permissions.

Examples:

  • To make a bash script executable for the owner:
    chmod u+x script.sh
  • To remove write permissions from everyone else (public):
    chmod o-w report.txt
  • To add read permissions for the group:
    chmod g+r document.pdf
  • To add execute permissions for everyone (owner, group, and others):
    chmod +x program.bin (or chmod a+x program.bin)

Using the Numeric (Octal) Method

System administrators often prefer the numeric method because it allows you to set the exact permissions for all three user categories simultaneously using a three-digit code.

Each permission is assigned a number:

  • Read (r) = 4
  • Write (w) = 2
  • Execute (x) = 1
  • No permission = 0

You add these numbers together to create the desired permission set. For example, Read + Write (4 + 2) = 6.

The three digits in the command represent the User, Group, and Others, in that exact order.

Examples:

  • chmod 777 filename: (4+2+1, 4+2+1, 4+2+1) Gives absolute full control (read, write, execute) to everyone. This is highly insecure and generally discouraged.
  • chmod 755 script.sh: (4+2+1, 4+1, 4+1) The owner has full control (7). The group and others can only read and execute (5). This is the standard permission for executable scripts.
  • chmod 644 document.txt: (4+2, 4, 4) The owner can read and write (6). Everyone else can only read (4). This is the standard, safe permission for normal text files.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.