How to Change File Permissions in Linux (chmod command)
Updated on
•11 min read

In Linux, you can control file access through permissions, attributes, and ownership. This ensures that only authorized users and processes can read, modify, or execute files and directories.
This tutorial explains how to use the chmod command to change permissions on files and directories.
Linux File Permissions Overview
Before going further, let’s explain the basic Linux permissions model.
Every file and directory in Linux has an owner and a group, and is assigned permission access rights for three different classes of users:
- Owner (the user who owns the file)
- Group (users in the file’s group)
- Others (everyone else)
File ownership can be modified with chown
(for owner) and chgrp
(for group).
Three file permission types apply to each class:
- Read (r): View file contents or list directory contents
- Write (w): Modify file or add/remove items in a directory
- Execute (x): Run file as program/script or enter (cd) directory
Special bits (setuid, setgid, sticky) appear as s, S, t, or T in the execute position.
This concept allows you to specify which users are allowed to read, write, or execute the file.
File permissions can be viewed using the ls
command:
ls -l filename.txt-rw-r--r-- 12 linuxize users 12.0K Apr 8 20:51 filename.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +-----------> 7. Group
| | | | | +-------------------> 6. Owner
| | | | +--------------------------> 5. Alternate Access Method
| | | +----------------------------> 4. Others Permissions
| | +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File TypeBreakdown:
The first character shows the file type. It can be a regular file (
-), a directory (d), a symbolic link (l), or any other special type of file.The following nine characters represent the file permissions, three triplets of three characters each. The first triplet shows the owner permissions, the second one group permissions, and the last shows others permissions. The permissions can have a different meaning depending on the file type.
In the example (rw-r--r--):
- The file owner has read and write permissions (
rw-) - The group and others have only read permissions (
r--)
The permission types can have different effects, depending on whether they are set to a file or to a directory:
Permissions on Files
Permissions on Directories (Folders)
Using the chmod Command
The chmod command takes the following syntax:
chmod [OPTIONS] MODE FILE...The chmod command allows you to change the permissions on a file using either a symbolic or numeric mode or a reference file. We will explain the modes in more detail later in this article. The command can accept one or more files and/or directories separated by spaces as arguments.
Only the root, the file owner, or a user with sudo privileges can change the permissions of a file. Be extra careful when using chmod, especially when changing permissions recursively.
Symbolic (Text) Method
Syntax:
chmod [OPTIONS] [ugoa…][-+=]perms…[,…] FILE...The first set of flags ([ugoa…]) represent the users’ classes:
u- The file owner.g- The users who are members of the group.o- All other users.a- All users, identical tougo.
If the user’s flag is omitted, the default one is a, and the permissions that are set by umask
are not affected.
The second set of flags ([-+=]), the operation flags, defines whether the permissions are to be removed, added, or set:
-Removes the specified permissions.+Adds specified permissions.=Changes the current permissions to the specified permissions. If no permissions are specified after the=symbol, all permissions from the specified user class are removed.
The permissions (perms...) can be explicitly set using either zero or one or more of the following letters: r, w, x, X, s, and t. Use a single letter from the set u, g, and o when copying permissions from one user’s class to another user’s class.
When setting permissions for more than one user class ([,…]), use commas (without spaces) to separate the symbolic modes.
Below are some examples of how to use the chmod command in symbolic mode:
Give the members of the group permission to read the file, but not to write and execute it:
Terminalchmod g=r filenameRemove the execute permission for all users:
Terminalchmod a-x filenameRecursively remove the write permission for other users:
Terminalchmod -R o-w dirnameRemove the read, write, and execute permission for all users except the file’s owner:
Terminalchmod og-rwx filenameThe same can be also accomplished by using the following form:
Terminalchmod og= filenameGive read, write, and execute permissions to the file’s owner, read permissions to the file’s group, and no permissions to all other users:
Terminalchmod u=rwx,g=r,o= filenameAdd the file’s owner permissions to the permissions that the members of the file’s group have:
Terminalchmod g+u filenameAdd a sticky bit to a given directory:
Terminalchmod o+t dirname
Numeric (Octal) Method
Basic syntax:
chmod [OPTIONS] NUMBER FILE...In numeric mode, you set permissions for all three user classes (owner, group, and others) at once.
When using the numeric mode, you can set the permissions for all three user classes (owner, group, and all others) at the same time.
The NUMBER can be a 3 or 4 digits number.
When a three-digit number is used, the first digit represents the permissions for the file’s owner, the second for the file’s group, and the last for all other users.
Each write, read, and execute permissions have the following number value:
r(read) = 4w(write) = 2x(execute) = 1- no permissions = 0
The permissions number for a specific user class is the sum of the values of the permissions for that group.
To find out the file’s permissions in numeric mode, simply calculate the totals for all user classes. For example, to give read, write, and execute permission to the file’s owner, read and execute permissions to the file’s group, and only read permissions to all other users, you would do the following:
- Owner: rwx=4+2+1=7
- Group: r-x=4+0+1=5
- Others: r-x=4+0+0=4
Using the method above, we come up with the number 754, which represents the desired permissions.
To set up the setuid, setgid, and sticky bit flags use a four-digit number.
When the four-digit number is used, the first digit has the following meaning:
- setuid=4
- setgid=2
- sticky=1
- no changes = 0
The next three digits have the same meaning as when using a three-digit number.
If the first digit is 0, it can be omitted, and the mode can be represented with 3 digits. The numeric mode 0755 is equivalent to 755.
To calculate the numeric mode, you can also use another method (the binary method), but it is a little more complicated. Knowing how to calculate the numeric mode using 4, 2, and 1 is sufficient for most users.
You can check the file’s permissions in the numeric notation using the stat
command:
stat -c "%a" filename644Here are some examples of how to use the chmod command in numeric mode:
Give the file’s owner read and write permissions and only read permissions to group members and all other users:
Terminalchmod 644 dirnameGive the file’s owner read, write, and execute permissions, read and execute permissions to group members, and no permissions to all other users:
Terminalchmod 750 dirnameGive read, write, and execute permissions, and a sticky bit to a given directory:
Terminalchmod 1777 dirnameRecursively set read, write, and execute permissions to the file owner and no permissions for all other users on a given directory:
Terminalchmod -R 700 dirname
Using a Reference File
The --reference=ref_file option allows you to set the file’s permissions to be the same as those of the specified reference file (ref_file).
chmod --reference=REF_FILE FILEFor example, the following command will assign the permissions of file1 to file2:
chmod --reference=file1 file2Recursively Change the File’s Permissions
To recursively operate on all files and directories under the given directory, use the -R (--recursive) option:
chmod -R MODE DIRECTORYFor example, to change the permissions of all files and subdirectories under the /var/www directory to 755, you would use:
chmod -R 755 /var/wwwRecursive changes may affect unintended files and can be dangerous. When not sure, test with find ... -print first. You can also limit the scope with the find command.
Operating on Symbolic Links
Symbolic links
always have 777 permissions.
By default, when changing a symlink’s permissions, chmod will change the permissions on the file the link is pointing to.
chmod 755 symlinkChances are that instead of changing the target ownership, you will get a “cannot access ‘symlink’: Permission denied” error.
The error occurs because, by default, symlinks are protected on most Linux distributions, so you cannot operate on the target files. This option is set in /proc/sys/fs/protected_symlinks. 1 means enabled and 0 disabled. It is recommended not to disable the symlink protection.
Changing File Permissions in Bulk
Sometimes you need to bulk change file and directory permissions. The most common scenario is to recursively change the website’s files permissions to 644 and the directories permissions to 755.
Using the numeric method:
find /var/www/my_website -type d -exec chmod 755 {} \;
find /var/www/my_website -type f -exec chmod 644 {} \;Using the symbolic method:
find /var/www/my_website -type d -exec chmod u=rwx,go=rx {} \;
find /var/www/my_website -type f -exec chmod u=rw,go=r {} \;The find
command will search for files and directories under /var/www/my_website and pass each found file and directory to the chmod command to set the permissions.
Troubleshooting Common chmod Errors
Here are frequent issues and how to fix them:
“Permission denied” You don’t have the authority to change permissions. Fix: Use
sudo chmod ...or switch to root or the file owner.“No such file or directory” The path is incorrect, or the file doesn’t exist. Fix: Verify that the file exists with
ls, use absolute paths, or tab-complete.“Operation not permitted” (even with sudo) Caused by filesystem mounts (e.g., FAT/NTFS), immutable attributes, or SELinux/AppArmor. Fix: Check with the
mountcommand fornoexec/nodev; remove the immutable flag withchattr -i file; review security policies.Changes not applying to symbolic links Using
chmodon a symlink may fail due to protected_symlinks. Fix: Usechmodon the target file.Invalid mode errors (e.g., “invalid mode: ‘abc’”) Typo in symbolic or numeric mode. Fix: Double-check syntax; numeric modes must be 3-4 digits (e.g., no leading zeros beyond 4 digits).
Use chmod --verbose to see what changes are applied, and always verify afterward with ls -l.
Conclusion
The chmod command is essential for managing file permissions in Linux, using symbolic, numeric, or reference modes.
For full details, visit the chmod man page.
If you have any questions or feedback, feel free to leave a comment.


