Linux Permissions and Ownership

Linux file permissions and ownership are fundamental security mechanisms

← Back to Linux Basics

Linux File Permissions & Ownership

Linux file permissions and ownership are fundamental security mechanisms that control who can read, write, or execute files and directories.

Ownership

Every file and directory in Linux has an owner and a group.

You can view ownership and permissions using:

ls -l filename

Example output: drwxr-xr-- user group filename
The 5th column shows the owner and the 6th column shows the group.

Permissions

Permissions are assigned to each ownership type (user, group, others) using three privileges: read, write, and execute.

Permission Symbol Files Directories
Read r View file contents List directory contents
Write w Modify or delete the file Create, delete, or rename files
Execute x Run the file as a program or script Enter (cd) the directory and access metadata

Modifying Permissions & Ownership

1. Changing Permissions (chmod)

You can use either symbolic notation or absolute (octal) mode.

Symbolic Notation

Use u (user), g (group), o (others), or a (all), along with + (add), - (remove), or = (set).

      
        chmod u+x filename     # Add execute permission for owner
        chmod o-rw filename    # Remove read & write for others
        chmod a=rwx filename   # Set full permissions for everyone
      

Absolute (Octal) Mode

Each permission has a numeric value:

      
        rwx = 7
        rw- = 6
        r-x = 5
        r-- = 4
        --- = 0
     
    

        chmod 755 filename   # Owner: rwx, Group: r-x, Others: r-x
        chmod 600 filename   # Owner: rw-, Group: ---, Others: ---
    

2. Changing Ownership (chown & chgrp)

These commands usually require sudo privileges.


      sudo chown user:group filename   # Change owner and group
      sudo chown user filename         # Change owner only
      sudo chgrp group filename        # Change group only