Skip to main content

Command Palette

Search for a command to run...

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

Updated
4 min read
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 chown to change ownership

  • Understanding file and directory permissions

  • Using chmod with numeric and symbolic notation

  • Practical 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 → owner

  • root → 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 privileges

  • chown → change ownership

  • root:root → new owner and group

  • example.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

SectionMeaning
-Regular file
rw-Owner permissions
rw-Group permissions
r--Others

Permission Symbols

SymbolMeaning
rRead
wWrite
xExecute
-Permission denied

Changing File Permissions with chmod (Numeric Mode)

The numeric (octal) method is concise and widely used.

Permission Values

PermissionValue
Read4
Write2
Execute1

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:

PermissionDirectory Meaning
rList contents (ls)
wCreate/delete files
xEnter 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?

RolePermissions
Ownerrwx (7)
Groupr-x (5)
Othersr-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 permission

  • x → execute

Verify:

ls -l script.sh
-rwxrw-r--

Now run it:

./script.sh

✅ Output:

Hello, World

Numeric vs Symbolic chmod

MethodBest For
Numeric (755)Setting full permission sets
Symbolic (u+x)Small, targeted changes

Key Takeaways

  • chown controls ownership

  • chmod controls permissions

  • Files need execute (x) permission to run

  • Directories need execute (x) permission to be accessed

  • Use -R carefully — recursive changes can be dangerous

  • Always 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 🐧✨


More from this blog

A

Aakib'z Studio

121 posts

I share practical insights on powerful development frameworks, focusing on Next.js for modern web apps and Flutter for efficient cross-platform mobile app development.