DevOps Bootcamp · Lesson

Understanding File Permissions (chmod, chown)

Learn about Linux file permissions, how they protect your data, and how to change them using 'chmod' and 'chown'.

Lesson 2 of 412 steps

Understanding File Permissions (chmod, chown) is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

What are File Permissions?

Welcome! In Linux, file permissions are security settings that control who can access and modify files and directories. They are crucial for protecting your data and ensuring system stability.

Think of them as digital bouncers for your files, deciding who gets in and what they can do once inside.

Read, Write, Execute (rwx)

There are three basic types of permissions:

  • Read (r): Allows viewing the content of a file or listing the contents of a directory.
  • Write (w): Allows modifying or deleting a file, or creating/deleting files within a directory.
  • Execute (x): Allows running a file (if it's a script or program) or entering a directory.

User, Group, Others (ugo)

These permissions are applied to three categories of users:

  • User (u): The owner of the file or directory.
  • Group (g): Users who belong to the file's primary group.
  • Others (o): All other users on the system.
  • Sometimes you'll see 'a' for 'all' (user, group, and others).

Viewing Permissions with ls -l

You can see a file's permissions using the ls -l command. Let's break down its output:

-rwxr-xr-- 1 user group 1024 Jan 1 10:00 myfile.txt

  • The first character (-) indicates the file type (- for regular file, d for directory).
  • The next nine characters (rwxr-xr--) represent the permissions.
ls -l important_doc.txt

Decoding Permission Strings

The nine permission characters are grouped into three sets of three:

  • 1st set (rwx): Permissions for the User (owner).
  • 2nd set (r-x): Permissions for the Group.
  • 3rd set (r--): Permissions for Others.

A hyphen (-) means that permission is not granted for that category.

Changing Permissions with chmod

The chmod command (change mode) is used to modify file and directory permissions. There are two main ways to use chmod:

  1. Symbolic mode: Uses letters and symbols (e.g., u+x).
  2. Octal (numeric) mode: Uses numbers (e.g., 755).

chmod: Symbolic Mode in Action

Symbolic mode is intuitive. You specify the category (u, g, o, a), the action (+ to add, - to remove, = to set exactly), and the permission (r, w, x).

  • chmod u+x myscript.sh: Adds execute permission for the owner.
  • chmod g-w myfile.txt: Removes write permission for the group.
  • chmod o=r-x mydir: Sets read-only for others, removing write.
echo '#!/bin/bash\necho Hello' > script.sh
chmod u+x script.sh
ls -l script.sh

chmod: Octal Mode Explained

Octal mode uses numbers to represent permissions. Each permission type has a value:

  • Read (r): 4
  • Write (w): 2
  • Execute (x): 1

You sum these values for each category (user, group, others). For example, rwx is 4+2+1=7, and r-x is 4+0+1=5.

chmod: Octal Mode Examples

You provide a three-digit number to chmod, representing user, group, and others permissions respectively.

  • chmod 755 mydir: User gets rwx (7), Group gets r-x (5), Others get r-x (5). Common for directories.
  • chmod 644 myfile.txt: User gets rw- (6), Group gets r-- (4), Others get r-- (4). Common for files.
touch report.txt
chmod 644 report.txt
ls -l report.txt

Changing Ownership with chown

The chown command (change owner) changes the user owner of a file or directory. This command usually requires superuser (root) privileges.

chown newuser myfile.txt

You can also change the group owner at the same time:

chown newuser:newgroup myfile.txt

touch testfile.txt
# sudo chown newuser testfile.txt
ls -l testfile.txt

Permission Challenge!

You have a file named private_note.txt. You want to set its permissions so that:

  • The owner can read and write.
  • The group can only read.
  • Others have no permissions at all.

Which of the following commands would achieve this?

Recap & Next Steps

Great job! You've mastered the fundamentals of Linux file permissions:

  • Understood read, write, execute permissions.
  • Learned about user, group, and others categories.
  • Used ls -l to view permissions.
  • Applied chmod in both symbolic and octal modes to change permissions.
  • Discovered chown to change file ownership.

Protecting your files is a key skill in Linux. Next, you'll learn how to search for files and patterns!

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Understanding File Permissions (chmod, chown)” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Understanding File Permissions (chmod, chown)”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Understanding File Permissions (chmod, chown)”?

Learn about Linux file permissions, how they protect your data, and how to change them using 'chmod' and 'chown'. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Understanding File Permissions (chmod, chown)” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Viewing File Content (cat, less, head, tail)
  2. Understanding File Permissions (chmod, chown)
  3. Searching for Files (find, grep)
  4. Creating Links: Hard Links & Symlinks
← Back to DevOps Bootcamp