Understanding Linux File Permissions & Ownership - Part 2

Chandana ReddyChandana Reddy
8 min read

Building on Part 1, this section focuses on how to secure your system effectively using Linux’s permission and ownership model. You’ll learn how to view file permissions, modify them using chmod, and manage ownership using chown and chgrp.

This part is all about controlling who can read, write, or execute files—and how to change those rights safely. These are critical skills for maintaining a secure and organized Linux environment, whether you're a beginner or managing servers in production.

Let’s dive into the essential Linux commands and concepts that help you secure your system using file permissions and ownership. From head and tail to chmod, chown, and chgrp, this guide will walk you through practical examples every Linux user should know.

First, we'll create a file. You can create a file using: touch myfile
After running ls -l (or) ll. You might see output like: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile

Understanding the Output: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile
Breakdown:
- → Type of file (in this case, a regular file)
rw- → Owner (read & write permissions)
r-- → Group (read-only)
r-- → Others (read-only)
1 → Number of hard links
root → Owner name
root → Group name
0 → File size (in bytes)
Aug 14 20:26 → Last modified date and time
myfile → File name

File Types in Linux:
- (hypen) - Regular file
d - Directory
c - Character device file
b - Block device file

File Permissions in Linux: Example: rw-r--r-- : This string has 9 characters, broken down into three sets:
rw- Related to User (owner) permissions. (Read & write)
r-- Related to group permissions. (Read only)
r-- Related to others - processors (backend permissions). Read only (everyone else)

Permission Values (Numeric Representation): Each permission is assigned a value:
r = 4 (read)
w = 2 (write)
x = 1 (execute)
- = 0 (no permission)

Permissions are added together to get a numeric value for each section:

rw- :Read + Write → 4 + 2 = 6
r-- :Read only → 4 + 0 = 4
r-- :Read only → 4 + 0 = 4
So, rw-r--r-- = 644

Execute Permission (x): Needed to run or execute scripts and programs. Without x, even if you can read a script, you cannot run it.

Understanding Permission Values in Linux: Linux file permissions are represented both symbolically
(e.g., rwx) and numerically (e.g., 7).

Example: Calculating Permission Values

User: rwx → 4 + 2 + 1 = 7
Group: --x → 0 + 0 + 1 = 1
Others: -w- → 0 + 2 + 0 = 2
So, permission value = 712

→ To Change Permissions of a File: Use the chmod command: chmod 712 filename

→To give full permissions to everyone: Use: chmod 777 filename
User: rwx = 4+2+1 = 7
Group : rwx = 4+2+1 = 7
Others : rwx = 4+2+1 = 7

: chmod stands for change mode.
: 777 gives full permissions to user, group, and others. This makes the file readable, writable, and executable by everyone — use with caution on servers!

Note: Giving 777 is risky, especially on servers — anyone can read, write, and execute the file.

Why This Matters: When working on servers, you often need to adjust file permissions to control who can access or modify a file. Knowing these values helps you use chmod efficiently.

Default Permission: 644
When you create a file (like with touch or vim), it often has: -rw-r--r--
rw- :Read + Write → 4 + 2 = 6
r-- :Read only → 4 + 0 = 4
r-- :Read only → 4 + 0 = 4
So the numeric value is 644 (default for most regular files).

To Add Extra Permissions to a File: Use the chmod +x command to add execute (x) permission:
chmod +x filename - This adds execute permission for user, group, and others.

Ex: Before: -rw-r--r--
User: rw- (read, write)
Group: r-- (read only)
Others: r-- (read only)

After running chmod +x filename
-rwxr-xr-x

User: rwx (read, write, execute)
Group: r-x (read, execute)
Others: r-x (read, execute)

Notes: +x adds execute permission. You can also target specific users:
chmod u+x filename → adds execute permission to the user only.
chmod g+x filename → adds execute to group.
chmod o+x filename → adds execute to others.

To Remove Extra Permissions to a File:

chmod -x filename : This command removes execute (x) permission from user, group, and others for the given file.

Ex: Before: -rwxr-xr-x
User: rwx
Group: r-x
Others: r-x

After running: chmod -x filename
-rw-r--r-- : The execute permission is removed from everyone.

To remove execute permission selectively:
chmod u-x filename → removes execute from user
chmod g-x filename → removes execute from group
chmod o-x filename → removes execute from others

Changing Permissions for Multiple Files at Once: Yes, you can change permissions for multiple files in a single command using chmod.
Syntax: chmod permission_value filename1 filename2..

Example: chmod 644 file1.txt file2.txt file3.txt
→This sets permission 644 (rw-r--r--) for all three files at once.
→ Useful when managing multiple files with the same required permissions.

Let’s Try It Step-by-Step:
Create sample files: touch aws swiggy zomato
Change permissions for all files: chmod 622 amazon swiggy zomato
Use ls -l (or) ll to verify the changes.

To Give Permissions to All Files in the Current Directory chmod 644 * . This command sets permission 644 (rw-r--r--) for all files in the current directory.* is a wildcard that matches all files (but not hidden files starting with .). It does not affect subdirectories or files inside them.

To Delete All Files in the Current Directory: rm -rf *
rm = remove
-r = recursive (removes directories and their contents)
-f = force (no confirmation)
* = all files and folders in the current directory

⚠️ Warning: This is a dangerous command. It will permanently delete everything in the current directory without asking for confirmation.

Create a Folder and Add Files:
To create a folder: mkdir myfolder
go to the folder: cd myfolder/
create files inside the folder: touch aws swiggy prime zomato
→ This creates a folder called myfolder and four files inside it.

🔙 Go Back to Root (or Parent Directory): cd ..

Set Permissions Only on the Folder (Not Files Inside): chmod 666 myfolder
→ This only changes permissions on the folder itself, not on the files inside it.
→ The folder will have rw-rw-rw- permissions, but the files inside will retain their original permissions.

To Set Permissions on Folder and Everything Inside (Recursively):
chmod -R 666 myfolder (or) chmod permissionvalue foldername -R
Ex: chmod 666 myfolder -R

-R stands for recursive. This applies the permission to the folder and all its contents (files and subdirectories).

To Give Permissions Only to Files Inside a Folder: chmod 777 myfolder/*

→ This applies 777 (rwxrwxrwx) permissions to all files directly inside myfolder.
→ It does not change the permission of the myfolder directory itself or subdirectories (if any)

To View Permissions of Files Inside the Folder: ll (or) ll myfolder/ (or) ls -l myfolder/ - This will list all files inside myfolder along with their permissions.

Example File Details: -rw-r--r--. 1 root root 0 Aug 14 20:26 myfile

Let’s break it down: -rw-r--r--. → Default file permissions
1 → Link count - this means the number of hard links
root root → File ownership: (1st root = User (owner of the file) ; 2nd root = Group (group that owns the file))

Note: The user who creates the file becomes its owner, and by default, the file is also assigned to a group with the same name (unless otherwise specified).

How to Change the Owner (User) of a File: Use the chown command: chown username filename
Example: chown chandana aws - This changes the owner of the file aws to the user chandana.
chown stands for change owner.

How to Change the Group Owner of a File: Use the chgrp command: chgrp groupname filename
: chgrp = change group. This command changes the group ownership of a file or directory.

Example: chgrp chandana xyz - This changes the group owner of the file xyz to the group chandana.

→ To check the current user and group ownership: ls -l filename (or) ll

→ To Change Both User and Group Ownership of a File: Use the chown command with the following.
Syntax: chown username:groupname filename

→ chown username:groupname folder is used to change both the owner and group of a folder at the same time.

chown -R username:groupname folder is used to change both the owner and group of a folder, including all files and subdirectories inside it, recursively.

chown username:groupname folder/* is used to change the owner and group of all files and subfolders directly inside the specified folder, but not recursively.

🔚 Conclusion:

Understanding chmod, chown, and permission bits isn’t just about syntax—it’s about shaping how your system behaves, protects, and collaborates. These commands give you the power to define boundaries, enforce security, and maintain clarity in a multi-user environment.

With commands like cat, head, and tail, inspecting data becomes second nature. And with tools like chmod, chown, and chgrp, you gain full control over how your files are accessed and by whom. The terminal isn’t just a tool—it’s your playground. Every command you run is a step toward deeper understanding, greater control, and true mastery of Linux.

As you experiment with permission settings and ownership changes, you’ll begin to see the elegance behind Linux’s access control model. So, keep exploring, keep experimenting, and let the command line be your canvas for learning and growth.

If you have questions or thoughts, feel free to leave a comment or share this with fellow tech enthusiasts! Thanks for reading🙏

Happy exploringand may your terminal never throw a permission denied at you again! 😄🔐

0
Subscribe to my newsletter

Read articles from Chandana Reddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chandana Reddy
Chandana Reddy

Hi, I'm Chandana—a curious soul navigating the world through study, reflection, and shared wisdom. My journey is rooted in self-education: exploring new ideas, skills, and perspectives that empower personal growth. I believe that learning isn’t limited to classrooms—it’s an everyday practice that transforms who we are and how we connect. Through writing, conversations, and community-building, I share insights and tools that help others learn with purpose and passion. I’m not just a student of life—I’m a contributor to its knowledge ecosystem.