Understanding Linux File Ownership and Permissions (chown & chmod Explained)

Managing file ownership and permissions is a core Linux skill. Whether you’re working on servers, deploying applications, or writing shell scripts, understanding how Linux controls access to files and directories is critical for both security and functionality.
In this article, we’ll explore:
File ownership in Linux
Using
chownto change ownershipUnderstanding file and directory permissions
Using
chmodwith numeric and symbolic notationPractical examples with files and scripts
File Ownership in Linux
Every file and directory in Linux has:
An owner (user)
A group
Permissions that define who can read, write, or execute it
You can view ownership and permissions using:
ls -l
Example output:
-rw-rw-r-- 1 root root 0 Jul 29 15:11 example.txt
Here:
root→ ownerroot→ group
Changing Ownership with chown
The chown command allows you to change the owner and group of a file or directory.
Basic Syntax
sudo chown owner:group filename
Example: Change File Ownership
sudo chown root:root example.txt
Explanation:
sudo→ runs the command with root privilegeschown→ change ownershiproot:root→ new owner and groupexample.txt→ target file
⚠️ Without
sudo, you’ll usually get a Permission denied error.
Working with Directories Recursively
Let’s create a directory structure with files:
mkdir -p new-dir/subdir
echo "Hello, world" > new-dir/file1.txt
echo "Another file" > new-dir/subdir/file2.txt
List everything recursively:
ls -lR new-dir
Change Ownership Recursively
sudo chown -R root:root new-dir
-R→ applies the ownership change to all files and subdirectories
Without -R, only the top-level directory would change ownership.
Understanding Linux File Permissions
Consider this permission string:
-rw-rw-r--
Breaking It Down
| Section | Meaning |
- | Regular file |
rw- | Owner permissions |
rw- | Group permissions |
r-- | Others |
Permission Symbols
| Symbol | Meaning |
r | Read |
w | Write |
x | Execute |
- | Permission denied |
Changing File Permissions with chmod (Numeric Mode)
The numeric (octal) method is concise and widely used.
Permission Values
| Permission | Value |
| Read | 4 |
| Write | 2 |
| Execute | 1 |
Example: Owner-Only Access
sudo chmod 700 example.txt
Meaning:
Owner → read + write + execute (7)
Group → no permissions (0)
Others → no permissions (0)
Result:
-rwx------
Directory Permissions Explained
Directory permissions behave slightly differently:
| Permission | Directory Meaning |
r | List contents (ls) |
w | Create/delete files |
x | Enter directory (cd) |
Example: Secure Directory
mkdir ~/test-dir
chmod 700 ~/test-dir
Check permissions:
ls -ld ~/test-dir
Output:
drwx------ 2 user user 4096 Jul 29 15:45 test-dir
Making a Directory Publicly Readable
chmod -R 755 ~/test-dir
What Does 755 Mean?
| Role | Permissions |
| Owner | rwx (7) |
| Group | r-x (5) |
| Others | r-x (5) |
Result:
drwxr-xr-x
Anyone can now list and access files, but only the owner can modify them.
Symbolic Permissions (Human-Friendly)
Symbolic notation is useful when you want to add or remove specific permissions.
Create a Script
cd ~/project
echo '#!/bin/bash\necho "Hello, World"' > script.sh
Check permissions:
ls -l script.sh
-rw-rw-r--
Try running it:
./script.sh
❌ Permission denied
Adding Execute Permission with Symbolic Mode
chmod u+x script.sh
Explanation:
u→ user (owner)+→ add permissionx→ execute
Verify:
ls -l script.sh
-rwxrw-r--
Now run it:
./script.sh
✅ Output:
Hello, World
Numeric vs Symbolic chmod
| Method | Best For |
Numeric (755) | Setting full permission sets |
Symbolic (u+x) | Small, targeted changes |
Key Takeaways
chowncontrols ownershipchmodcontrols permissionsFiles need execute (
x) permission to runDirectories need execute (
x) permission to be accessedUse
-Rcarefully — recursive changes can be dangerousAlways double-check commands when using
sudo
Final Thoughts
Linux permissions are the foundation of system security. Once you understand how ownership and permissions work together, managing servers and applications becomes much safer and more predictable.
If you’re learning Linux seriously, mastering chown and chmod is non-negotiable.
Happy hacking 🐧✨





