How to Change File and Directory Permissions via the Linux Terminal

In Linux, each file and directory has three permission categories and three basic types of permissions.

Managing file and directory permissions is essential for securing a Linux system. Every file and folder has defined permissions that control who can read, write, or execute it. This guide provides a clear, structured breakdown of how to inspect and modify these permissions using the terminal.

Understanding Linux File Permission Structure

In Linux, each file and directory has three permission categories and three basic types of permissions:

Permission Categories

  • User (u) – The owner of the file.
  • Group (g) – Other users in the same group as the file.
  • Others (o) – Everyone else.

Permission Types

  • Read (r) – View the contents of a file or list a directory’s contents.
  • Write (w) – Modify the file or add/remove contents in a directory.
  • Execute (x) – Run the file as a program or enter the directory.

Viewing Current Permissions

To check permissions of files and directories, use:

bash

CopyEdit

ls -l

This command lists files with their permissions in the format:

bash

CopyEdit

-rw-r--r-- 1 user group 1234 May 22 20:00 example.txt

Explanation of this output:

  • -rw-r--r-- – Permission string:
    • User: rw- (read, write)
    • Group: r-- (read)
    • Others: r-- (read)
  • 1 – Number of hard links
  • user – File owner
  • group – File group
  • 1234 – File size in bytes
  • May 22 20:00 – Last modification date
  • example.txt – File name

Changing Permissions with chmod

Linux uses the chmod command to modify permissions. There are two methods:

Method 1: Symbolic Mode

Symbolic mode uses letters and operators to represent permission changes.

Syntax:

bash

CopyEdit

chmod [user category][operator][permission] [file/directory]

User Categories:

  • u – user (owner)
  • g – group
  • o – others
  • a – all users

Operators:

  • + – add permission
  • - – remove permission
  • = – set exact permission

Examples:

Remove write permission from user:
bash
CopyEdit
chmod u-w file.txt

Add execute permission to group:
bash
CopyEdit
chmod g+x script.sh

Give read/write to all users:
bash
CopyEdit
chmod a=rw shared.txt

Method 2: Numeric (Octal) Mode

Each permission is represented numerically:

Permission

Value

Read (r)

4

Write (w)

2

Execute (x)

1

You add the values to get a single digit for each category.

Syntax:

bash

CopyEdit

chmod [three-digit number] [file/directory]

Examples:

Set rw-r--r-- (user: read/write, group & others: read):
bash
CopyEdit
chmod 644 file.txt

Set rwxr-xr-x (user: all, group & others: read/execute):
bash
CopyEdit
chmod 755 program.sh

Set rwx------ (user: all, no access for others):
bash
CopyEdit
chmod 700 private.txt

Changing Directory Permissions

Directories require execute (x) permission to be accessible. Use chmod the same way as for files.

Directory Examples:

Give user execute permission on a directory:
bash
CopyEdit
chmod u+x my_folder

Remove write permission from others:
bash
CopyEdit
chmod o-w my_folder

Apply changes recursively to all subdirectories and files:
bash
CopyEdit
chmod -R 755 /var/www

Combining Multiple Changes

You can combine multiple symbolic permission changes in one command.

Example:

Add read for group, remove execute from others:
bash
CopyEdit
chmod g+r,o-x data.txt

Special Permission Bits

Beyond standard permissions, Linux supports special bits for advanced use:

Setuid (Set User ID)

  • Applies to executables.
  • When executed, runs with file owner's privileges.

bash

CopyEdit

chmod u+s /usr/bin/special_program

Setgid (Set Group ID)

  • When applied to a directory, new files inherit its group.
  • For executables, runs with group privileges.

bash

CopyEdit

chmod g+s /projects/team_dir

Sticky Bit

  • Applied to shared directories.
  • Users can only delete their own files.

bash

CopyEdit

chmod +t /shared_folder

Best Practices for Permission Management

  1. Use ls -l Frequently – Always verify permission settings before and after changes.
  2. Limit Recursive Changes – Only use -R when absolutely necessary.
  3. Follow Least Privilege Principle – Grant only the permissions needed.
  4. Avoid 777 Permissions – Full access to everyone should be avoided in production environments.

By mastering permission management with chmod, you can protect sensitive files, manage access, and maintain control over your Linux environment with precision and confidence.

Support.Com Can Help!

If you’re still having trouble, consider reaching out to Support.Com for a personalized solution to all technical support issues.