USD ($)
$
United States Dollar
Euro Member Countries
India Rupee

Modifying Permissions and Ownership

Lesson 14/49 | Study Time: 15 Min

In Linux, the ability to modify file and directory permissions and ownership is crucial for maintaining security, privacy, and orderly access control. Permissions determine who can read, write, or execute a file, while ownership associates files with specific users and groups. 

Changing File and Directory Permissions with chmod

The chmod (change mode) command is used to set or modify the read (r), write (w), and execute (x) permissions for user categories: owner (u), group (g), and others (o). Permissions can be changed either symbolically or numerically.


Symbolic Mode: Permissions are added (+), removed (-), or set (=) for specific user classes.

Syntax example:

text
chmod u+x filename # Adds execute permission to the owner
chmod g-w filename # Removes write permission from the group
chmod o=r filename # Sets others' permissions to read only


User classes:


  • u user (owner)
  • g group
  • o others
  • aall (user, group, others)


Numeric (Octal) Mode: Permissions represented by numbers: read=4, write=2, execute=1

Add the values to set combined permissions:


7 (4+2+1) = read, write, execute

6 (4+2) = read, write

5 (4+1) = read, execute


Syntax example:

text
chmod 755 filename # rwx for owner, rx for group and others
chmod 644 filename # rw for owner, r for group and others

Changing Ownership with chown

Ownership associates files and directories with a user and group.


1. To change the owner:

text
chown username filename


2. To change owner and group together:

text
chown username:groupname filename


3. To change only the group:

text
chown :groupname filename


4. To change ownership recursively (all files/directories inside a folder):

text
chown -R username:groupname directoryname


Note: Changing ownership usually requires superuser (root) privileges, so prepend commands with sudo where necessary.

Changing Group Ownership with chgrp

The chgrp command specifically modifies the group owner of a file or directory:

text
chgrp groupname filename


It is a simpler alternative to chown when only the group needs changing.

Practical Examples


1. Add execute permission for the user and group on a script:

text
chmod ug+x script.sh


2. Change ownership of a file to user "john" and group "developers":

text
sudo chown john:developers project.txt


3. Recursively change group ownership for all files inside /var/www to www-data:

text
sudo chgrp -R www-data /var/www


4. Remove write permission for others on a file:

text
chmod o-w confidential.txt

Important Points


1. Only the file owner or root can modify permissions and ownership.

2. Incorrect permission settings can expose files to unauthorized access or prevent legitimate usage.

3. Recursive changes (chmod -R, chown -R) should be used carefully.

4. Use ls -l to verify permissions and ownership after changes.

Samuel Wilson

Samuel Wilson

Product Designer
Profile

Class Sessions

1- What is Linux and Operating System Concepts 2- Linux History and Evolution 3- Linux Distributions and Their Purposes 4- Open Source Software and Licensing 5- Graphical User Interface (GUI) and Desktop Environments 6- Terminal Access and Command-Line Fundamentals 7- Getting Help and Command Documentation 8- File System Hierarchy and Directory Structure 9- Navigating Directories and Listing Contents 10- Creating, Copying, and Moving Files and Directories 11- Deleting Files and Directories 12- Symbolic and Hard Links 13- Understanding File Permissions Model 14- Modifying Permissions and Ownership 15- User and Group Management 16- Sudo and Privilege Escalation 17- Text Searching and Pattern Matching 18- Text Processing and Stream Editing 19- Compressing and Archiving Files 20- Text Editing and File Creation 21- Package Management Systems Overview 22- Installing and Updating Software with APT 23- Installing and Updating Software with YUM/DNF 24- Managing Software from Non-Repository Sources 25- Understanding Processes and Process Management 26- Viewing Running Processes 27- Process Control and Termination 28- Task Scheduling with Cron 29- Networking Concepts and IP Addressing 30- Viewing and Configuring Network Interfaces 31- Basic Network Troubleshooting 32- Shell Script Basics 33- Variables and Data Types 34- Conditional Logic in Scripts 35- Loops and Iteration 36- Functions and Code Reuse 37- Input/Output and User Interaction 38- System Authentication and Access Control 39- File System Security 40- Software Updates and Patching 41- Basic Firewall Concepts 42- System Information and Monitoring 43- Service and Daemon Management 44- System Boot Process and Runlevels 45- System Backup and Disaster Recovery 46- Comprehensive File System Management 47- System Automation Workflows 48- Multi-Concept Troubleshooting Scenarios 49- Continued Learning Pathways