Every file on a Linux system carries a set of access rules that determines who can read, write, or run it. When those rules are wrong, scripts fail, services break, and sensitive data becomes exposed. Knowing how to change permissions of a file in Linux lets you correct these issues quickly. The primary tool for this job is chmod. This guide covers both notation methods, recursive changes, and common errors you’re likely to run into.
How Linux File Permissions Work
Linux assigns access rules across three user categories. You can inspect them at any time using ls -l:
ls -l myfile.txt
The output shows a string like -rw-r--r--. The first character indicates the file type. The next nine characters are three groups of three, covering owner, group, and others in that order.
| Category | Who It Covers |
|---|---|
| Owner | The user who created the file |
| Group | Members of the assigned group |
| Others | All remaining users on the system |
| Permission | Symbol | Meaning |
|---|---|---|
| Read | r | View file contents |
| Write | w | Edit or delete the file |
| Execute | x | Run as a program or enter a directory |
How to Change Permissions of a File in Linux Using Symbolic Notation
Symbolic notation lets you add, remove, or set permissions without calculating numbers. The basic syntax is:
chmod [who][operator][permission] filename
For [who]: u targets the owner, g the group, o others, and a all three. Operators are + to grant, - to revoke, and = to set exactly. A few working examples:
chmod g=r report.txt
chmod a-x script.sh
chmod u=rwx,g=r,o= config.yml
The first grants read-only access to group members. The second strips execute access from everyone. The third gives the owner full control, allows group members to read, and blocks others entirely. See the full chmod man page for every available flag.
How to Change Permissions of a File in Linux Using Octal Notation
Octal (numeric) notation lets you set all three categories in a single three-digit code. Each permission maps to a number:
| Permission | Value |
|---|---|
| Read | 4 |
| Write | 2 |
| Execute | 1 |
| None | 0 |
Add the values together per category. rwx equals 7, r-x equals 5, r-- equals 4. So this command:
chmod 754 deploy.sh
…gives the owner full access (7), the group read and execute (5), and others read only (4). Verify the result with stat -c "%a" deploy.sh.
Applying Changes to Entire Directories
Add -R to apply chmod recursively across all nested files and subdirectories:
chmod -R 755 /var/www/project
When you need separate rules for files and directories, pair the find command with chmod:
find /var/www/project -type d -exec chmod 755 {} \;
find /var/www/project -type f -exec chmod 644 {} \;
This sets directories to 755 and regular files to 644, which is a standard web server layout.
Copying Permissions from Another File
The --reference flag copies the access settings from one file directly onto another:
chmod --reference=source.conf target.conf
This saves time when you need a new file to match an existing one exactly, without looking up the numeric value first.
Changing File Ownership
Permissions only go so far if the ownership is wrong. Use chown to transfer a file to a different user or group:
chown username:groupname filename
You need root access or sudo to change ownership of files you do not own.
Common Errors and Fixes
| Problem | Likely Cause | Fix |
|---|---|---|
| Permission denied | You lack write or execute access | Prefix the command with sudo |
| No such file or directory | The path is wrong | Confirm the path with ls |
| Operation not permitted | Filesystem restriction or SELinux policy | Check mount options or SELinux rules |
| Symlink not updating | Protected symlinks enabled | Run chmod on the actual target file, not the link |
For scripts specifically, see the chmod executable guide for mode recommendations based on whether a script is private, shared with a team, or meant for all users.
FAQs
What does chmod 777 mean in Linux?
chmod 777 grants read, write, and execute access to the owner, group, and all other users. Avoid it on production systems — it removes all access restrictions and exposes files to any user on the system.
How do I check current file permissions in Linux?
Run ls -l filename to see permissions in symbolic form, or stat -c "%a" filename to get the octal value. Both commands work on files and directories.
What is the difference between chmod and chown?
chmod changes what actions are allowed on a file (read, write, execute). chown changes who owns the file. You often need both when moving files between users or setting up a web server.
Can I change permissions on a file I do not own?
No, unless you have root or sudo access. Only the file owner or root can run chmod on a file. Running it as another user returns a “permission denied” or “operation not permitted” error.
What permissions should I use for shell scripts?
Use 700 for private scripts with sensitive operations, 750 for scripts shared with a team group, and 755 for system-wide utilities that all users need to run but only you should edit.