If you have ever fixed a “Permission denied” error by guessing and then broken a script, a shared folder, or a web directory, you already know why the chmod command matters. Linux file permissions are not just a security feature; they are a control mechanism for collaboration, service stability, and secure file management. One wrong Unix permission setting can stop a deployment, expose data, or let the wrong user write to the wrong file.
Certified Ethical Hacker (CEH) v13
Learn essential ethical hacking skills to identify vulnerabilities, strengthen security measures, and protect organizations from cyber threats effectively
Get this course on Udemy at the lowest price →In this article, you will learn how chmod works, how to read permission strings, and how to change permissions safely using both symbolic and numeric modes. You will also see practical examples for scripts, shared folders, directories, and web files. That matters for anyone working in security or administration, including people building the file-handling discipline expected in the Certified Ethical Hacker (CEH) v13 course, where weak permissions are a common finding during system review.
The baseline principle is simple: set only the access that is needed, and no more. That principle aligns with NIST guidance on least privilege and with common hardening practices seen in Microsoft Learn and Red Hat documentation for Linux administration.
Understanding Linux File Permissions
Linux file permissions are built around three access types: read, write, and execute. Read lets you view contents, write lets you modify contents, and execute lets you run a file as a program or enter a directory. Those three bits are applied across three permission categories: user (the owner), group, and others.
When you run ls -l, you see the permission string in long listing format. A file such as -rwxr-xr-- means the owner can read, write, and execute; the group can read and execute; and everyone else can only read. The first character shows the type: - for a regular file, d for a directory, and other letters for special objects. That format is the quickest way to see whether your secure file management choices match reality.
File permissions versus directory permissions
Directory permissions behave differently than file permissions, and this is where many administrators make mistakes. On a file, execute means “run this.” On a directory, execute means “traverse this path.” Without execute on a directory, you cannot access files inside it even if you know their names. Read on a directory lets you list names, while write lets you create or remove entries.
Ownership matters too. A file has a user owner and a group owner, and chmod works alongside chown and chgrp. If the ownership model is wrong, changing permissions alone may not solve the problem. That is why file access troubleshooting usually starts with the full picture: permissions, ownership, and group membership.
Note
A permission string answers three questions at once: who can access the object, what they can do, and whether the object is a file or directory. If you read ls -l carefully, you can usually diagnose the issue without guessing.
For a broader standards view, the IETF publishes protocol behavior that depends on correct file access on servers, while CIS Benchmarks repeatedly stress restrictive default permissions for service files and web content.
How Chmod Works
chmod is the command used to change permission bits on files and directories. It does not change ownership. That distinction matters: if the wrong user or group owns a file, chmod may only mask the real problem. You still need chown or chgrp when ownership is the issue.
The command supports two main styles: symbolic mode and numeric mode. Symbolic mode uses letters like u, g, and o with operators such as +, -, and =. Numeric mode uses octal values like 755 or 644. Both produce the same underlying result because permissions are stored internally as bits.
That internal bit structure explains why read, write, and execute map cleanly to numbers. Read is 4, write is 2, and execute is 1. When combined, they create values like 7, 6, 5, and 0. For example, 7 means all three bits are on, while 5 means read and execute only.
Recursive behavior and caution
chmod can also run recursively with -R, which applies changes through many files and subdirectories. That is useful for a project tree, but it can also cause damage fast. A recursive permission change on a shared directory or production web root can break services or expose private files if you do not check the target path first.
Permission changes are safest when you can explain the result before running the command. If you cannot predict what a recursive
chmodwill do, do not run it on production data.
Vendor documentation such as Red Hat documentation and man7 chmod are good references for exact behavior, especially when special bits and recursive patterns come into play.
Using Symbolic Mode
Symbolic mode is the readable way to use the chmod command. The syntax is simple: who gets changed, what operation is applied, and which permission is affected. For example, u+x means add execute permission for the user owner, while g-w means remove write permission from the group.
The three operators are straightforward. + adds permissions, - removes them, and = sets exact permissions. That last one is important because it replaces the existing setting rather than modifying it. If a file already has extra access you do not want, = is the cleanest way to reset it.
Common symbolic examples
- Make a script executable:
chmod u+x script.sh - Remove write access from the group:
chmod g-w report.txt - Grant read access to others:
chmod o+r file.txt - Add read and write to user and group at once:
chmod ug+rw file.txt
Symbolic mode is especially useful when you want to change one thing without touching the rest. If a script already has the correct read bits but lacks execute, chmod u+x fixes only that gap. That makes it ideal for secure file management because it minimizes unintended changes.
Symbolic mode also scales well when you are working from a troubleshooting perspective. If a service account cannot write to a log, you can try g+w on the directory or file after confirming ownership. That is often better than guessing a full numeric pattern and hoping it fits.
Pro Tip
Use symbolic mode when you are adjusting one specific permission and numeric mode when you are applying a known standard like 644 or 755. That simple rule reduces mistakes.
For access control concepts tied to defense and auditing, it helps to compare them with the SANS Institute approach to hardening and with Linux security guidance in official vendor docs. In security reviews, symbolic changes are easier to justify because they are explicit and readable.
Using Numeric Mode
Numeric mode is faster when you already know the permission pattern you want. It uses the values 4 for read, 2 for write, and 1 for execute. Combine them for each category. So 7 means 4+2+1, 6 means 4+2, 5 means 4+1, and 0 means no access.
The common patterns are easy to memorize. 755 means the owner gets full access, while group and others get read and execute. 644 means the owner can read and write, while group and others can only read. 700 means only the owner has access, which is common for private folders and sensitive scripts.
| Permission pattern | Typical use |
|---|---|
755 |
Executable scripts and public directories |
644 |
Text files, documents, and many config files |
700 |
Private folders, personal keys, sensitive data |
Numeric mode is often clearer when a standard is already defined. Web administrators, for example, may want consistent file modes for content and separate modes for directories. If you know the desired end state, numeric mode is concise and repeatable.
That said, numeric mode can be dangerous if you do not think through the effect on files versus directories. A directory usually needs execute to be useful, but a regular document does not. Copying a permission pattern blindly between the two can create access problems or open paths that should remain restricted.
Reference points for permission policy can be found in NIST CSF and Linux hardening materials from CIS, both of which emphasize controlled access and routine verification.
Common Permission Scenarios
Real permission work usually falls into a few patterns. A shell script often needs to run for the owner and perhaps be readable by others, but not writable. A text document usually needs read and write for the owner and read-only for everyone else. A private folder should usually block access from group and others completely.
Here is the logic behind those examples. Scripts need execute permission because the kernel must be able to launch them. Documents do not need execute because they are not programs. Configuration files often need to be readable by a service account but not writable by general users, especially when the file controls authentication, logging, or network behavior.
Shared folders and web files
Shared project folders usually work best with group-based access, not broad access to everyone. One common approach is to give the owner and group read-write permission while leaving others out. This supports collaboration without exposing the directory to every local user.
Web server files are more sensitive. A common setup is readable by the web service but writable only by administrators or deployment tooling. Overly permissive modes create risk because web content, scripts, and configuration files can be altered by unauthorized users if write access is too broad.
- Good for scripts:
755or750, depending on who should run them - Good for documents:
644 - Good for private folders:
700 - Usually avoid:
777
777 gives read, write, and execute to user, group, and others. That almost never belongs on a normal system file, web root, or shared directory. It can be acceptable only in a tightly controlled, temporary, and well-understood lab case, and even then it should be treated as a red flag.
Warning
Avoid using 777 as a shortcut. It hides the real ownership or application design problem and often creates an unnecessary security issue that shows up later in an audit.
These patterns align with hardening advice from OWASP for web assets and with file access recommendations in ISO 27001 programs, where minimal access and documented control are standard practice.
Working With Directories
Directory permissions deserve special attention because they control navigation as well as content. To enter a directory or access a file inside it, you need execute permission on that directory. To list the contents, you need read. To create or delete entries, you need write. Those are different actions, and Linux treats them separately.
That is why a directory can be readable but not traversable, or traversable but not listable. A common example is a directory with 750. The owner can fully manage it, the group can read and enter it, and others are blocked. This is a useful pattern for shared application folders, controlled project spaces, and service directories.
Examples that matter in practice
chmod 755 /var/www/html is common when a web server needs to read static content and users need to browse a site. chmod 750 shared_dir is more appropriate when the directory should only be visible to the owner and a trusted group. In both cases, the directory permissions must match how the files inside are used.
Recursive permission changes are especially risky with directories because nested files and folders do not all need the same mode. A directory may need execute, but a text file inside it should not. If you apply a single pattern blindly to an entire tree, you may create files that can be executed when they should not be, or directories that can no longer be entered.
For controlled administration, compare your results with ls -l and stat. On larger systems, that habit saves time. It also makes it much easier to explain your changes during audits, incident reviews, or handoffs.
For a security-oriented view of directory hardening, the CISA guidance on secure configuration and the Red Hat Enterprise Linux documentation are both practical references for real-world Linux administration.
Recursive Chmod And Bulk Changes
The -R flag tells chmod to apply changes recursively through directories. This is useful when you have a large codebase, a documentation tree, or a folder full of shared project content. It is also the fastest way to make a big mistake if you do not inspect the tree first.
A command like chmod -R u+rwX,go-rwx folder is a common hardening pattern because it gives the owner read and write, gives execute only where it is already needed on directories or executable files, and removes access for group and others. The uppercase X is important because it avoids granting execute to every file in the tree. That is a cleaner approach than using lowercase x everywhere.
When to use find instead of -R
If you need more control, use find. For example, apply one mode to files and another to directories. That lets you keep directories traversable while keeping regular files non-executable. It is often the right method on application trees where files and folders play different roles.
- Inspect the tree with
find folder -maxdepth 2 -lsorls -lR folder. - Decide which objects are files and which are directories.
- Apply permission changes separately if needed.
- Verify with
stator another listing command.
After any bulk change, check the outcome immediately. It is much easier to correct a permissions mistake while it is fresh than after a service fails or users report broken access. Bulk changes are not the time to assume.
For evidence-based security operations, the MITRE ATT&CK knowledge base helps explain why attackers often look for weak permissions and over-broad access on file systems. The pattern is familiar: if a process can write where it should not, that becomes a foothold.
Special Permission Bits
Beyond the standard read, write, and execute bits, Linux has three special permission bits: setuid, setgid, and the sticky bit. These are advanced features, not everyday tools. They are useful in specific cases, but they deserve caution because they can change how a system behaves in ways that are not obvious from a quick glance.
setuid causes an executable to run with the file owner’s privileges. setgid on an executable does the same for the group, and on a directory it often forces new files to inherit the directory’s group. The sticky bit on a directory, such as /tmp, prevents users from deleting each other’s files even though the directory is writable.
Practical examples and risk
Setgid is especially useful in shared directories where team files should remain in the same group. That reduces administrative cleanup and keeps collaboration smoother. The sticky bit matters on shared writable areas because it prevents one user from removing another user’s data just because both can write in the same directory.
These bits are visible in long listings, often as special letters in the execute position or with a lowercase or uppercase marker. Because they change behavior, they should be used only when you understand the application, the directory purpose, and the security effect. Incorrect use can create privilege escalation paths or unintentionally block normal access.
chmod can set these bits, but that does not mean it should do so casually. Administrative teams should document why a special bit exists, who depends on it, and how to verify it after changes. That discipline is part of real secure file management.
For formal treatment of privilege and control, NIST references and FIRST resources are useful when you need to connect file-level mistakes to broader vulnerability handling and response practices.
Troubleshooting Permission Problems
The most common symptom of bad permissions is the blunt message: Permission denied. That message can mean several things. The file may lack read or execute access. The directory may lack traverse permission. The user may not belong to the correct group. Or the ownership may be wrong, so permissions never had a chance to work properly.
A good troubleshooting flow is simple. First inspect the file or directory with ls -l and stat. Then check your identity with id. If group changes were made recently, remember that the shell session may not yet know about them. Logging out and back in, or refreshing the group context, can be enough to make the access work.
A practical workflow
- Inspect: Use
ls -l,stat, and if needednamei -lfor path traversal. - Compare: Check the permissions against a working file, script, or directory.
- Adjust: Use
chmod,chown, orchgrpas appropriate. - Verify: Re-run the command, list the path again, and test the application.
Do not assume the problem is always with the file itself. A file can be correct and still fail because one parent directory blocks traversal. That is why directory execute permission is so often overlooked. It is also why bulk permission fixes should be followed by actual functional testing, not just visual inspection.
For formal system administration references, the man page for id and the Linux documentation ecosystem remain useful, while workforce and security reports from CompTIA® continue to show that practical command-line troubleshooting remains a core operational skill.
Best Practices For Using Chmod Safely
The safest rule is also the simplest: start with the least permissive setting that still works. If a user needs only read access, do not grant write. If a service needs to traverse a directory but not list it, keep read off and grant only execute where needed. That approach protects both usability and security.
Prefer group-based collaboration over broad access for everyone. That means designing access around teams, services, and roles instead of defaulting to “others” permissions. When a file must be shared, give access to the relevant group and keep the rest blocked. That is more maintainable and much easier to audit.
Key Takeaway
Most permission problems are caused by overbroad access, wrong ownership, or confusion between file and directory behavior. If you understand those three points, chmod becomes a precise tool instead of a guess.
Practical rules to follow
- Avoid 777: Use it only in rare, controlled cases.
- Check system paths carefully: Be extra cautious with
/etc,/var/www,/home, and shared mounts. - Verify after every change: Run
ls -lorstatimmediately after applying permissions. - Test the real workload: Open the file, run the script, or restart the service to confirm behavior.
This is where operational discipline meets security. The BLS continues to list steady demand for computer and information technology roles, while ISC2® research and workforce studies consistently show that hands-on security basics still matter. File permissions are one of those basics. They are small, but they show up everywhere.
If you are studying practical Linux hardening as part of the CEH v13 skill set, permission management is worth practicing until it becomes automatic. The best ethical hackers do not just spot weak access; they understand exactly how to fix it without breaking the system.
Certified Ethical Hacker (CEH) v13
Learn essential ethical hacking skills to identify vulnerabilities, strengthen security measures, and protect organizations from cyber threats effectively
Get this course on Udemy at the lowest price →Conclusion
chmod is one of the most important Linux tools you will use for Linux file permissions and secure file management. It lets you change access through symbolic mode or numeric mode, handle directories correctly, apply changes recursively when needed, and work with advanced bits like setgid and the sticky bit. The key is to understand what you are changing before you change it.
Remember the essentials: read, write, and execute behave differently on files and directories; ownership and group membership matter just as much as permission bits; and broad settings like 777 should usually raise alarms, not approval. If you are unsure, test on a nonproduction file first, inspect the result with ls -l or stat, and confirm the behavior before moving on.
Good permission management is not just housekeeping. It improves usability, prevents avoidable outages, and reduces exposure. Practice with scripts, folders, and config files until the patterns are second nature. When you can set the right Unix permission setting quickly and accurately, you are doing more than using chmod well. You are making the system safer.
CompTIA® and Security+™ are trademarks of CompTIA, Inc. ISC2® and CISSP® are trademarks of ISC2, Inc. Microsoft® is a trademark of Microsoft Corporation. Red Hat® is a trademark of Red Hat, Inc.