Understanding File Permissions (chmod, chown)
Learn about Linux file permissions, how they protect your data, and how to change them using 'chmod' and 'chown'.
Understanding File Permissions (chmod, chown) is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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,dfor directory). - The next nine characters (
rwxr-xr--) represent the permissions.
ls -l important_doc.txtDecoding 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:
- Symbolic mode: Uses letters and symbols (e.g.,
u+x). - 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.shchmod: 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.txtChanging 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.txtPermission 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 -lto view permissions. - Applied
chmodin both symbolic and octal modes to change permissions. - Discovered
chownto change file ownership.
Protecting your files is a key skill in Linux. Next, you'll learn how to search for files and patterns!
Frequently asked questions
Is the “Understanding File Permissions (chmod, chown)” lesson free?
Yes — the full text of “Understanding File Permissions (chmod, chown)” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
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
- Viewing File Content (cat, less, head, tail)
- Understanding File Permissions (chmod, chown)
- Searching for Files (find, grep)
- Creating Links: Hard Links & Symlinks