Linux is widely used for web servers, cloud infrastructure, development environments, DevOps, and system administration. One of the most important concepts in Linux is file and directory permissions.
Permissions determine who can read, modify, or execute a file or access a directory. The Linux chmod command allows developers and system administrators to change these permissions quickly and securely.
In this guide, we will understand what chmod means, how Linux permissions work, and how to use the chmod command with practical examples.
What Is the chmod Command?
chmod stands for change mode. It is a Linux and Unix command used to change the access permissions of files and directories.
A basic syntax is:
chmod [options] mode file
For example:
chmod 755 script.sh
This changes the permissions of script.sh so that the owner can read, write, and execute it, while the group and other users can read and execute it.
Understanding Linux File Permissions
Before using chmod, it is important to understand the three basic permission types:
Read (r) – Allows a user to view the contents of a file.
Write (w) – Allows a user to modify a file.
Execute (x) – Allows a user to execute a file or access a directory.
Linux permissions are assigned to three categories of users:
User/Owner (u) – The owner of the file.
Group (g) – Users belonging to the file's group.
Others (o) – Everyone else.
You can check permissions using:
ls -l
You may see something like:
-rwxr-xr--
The first character represents the file type. The remaining characters represent permissions for the owner, group, and others.
Using chmod With Symbolic Permissions
The symbolic method uses letters to specify which permissions should be changed.
Common symbols include:
u – user/owner
g – group
o – others
a – all users
+ – add permission
- – remove permission
= – assign exact permissions
Add Execute Permission
To give the owner execute permission:
chmod u+x script.sh
Remove Write Permission
To remove write permission from others:
chmod o-w file.txt
Add Read Permission for Everyone
chmod a+r file.txt
Give Group Execute Permission
chmod g+x script.sh
Symbolic permissions are useful when you want to make a small, specific permission change without changing everything else.
Using chmod With Numeric Permissions
The numeric method is one of the most common ways to use chmod.
Each permission has a numeric value:
Read = 4
Write = 2
Execute = 1
You add these values together to create a permission level.
For example:
Read + Write + Execute
4 + 2 + 1 = 7
Read + Write
4 + 2 = 6
Read + Execute
4 + 1 = 5
Read only
4
This gives us common permission combinations such as:
7 = rwx
6 = rw-
5 = r-x
4 = r--
3 = -wx
2 = -w-
1 = --x
0 = ---
Understanding chmod 755
One of the most commonly used permission settings is:
chmod 755 filename
It means:
Owner: 7 → read, write, execute
Group: 5 → read, execute
Others: 5 → read, execute
In symbolic form:
rwxr-xr-x
This is commonly suitable for executable files, scripts, and directories where the owner needs full control while other users only need access.
Understanding chmod 644
Another common permission setting is:
chmod 644 file.txt
This means:
Owner: read and write
Group: read
Others: read
The resulting permission is:
rw-r--r--
This is commonly used for regular files that users need to read but should not modify.
Making a Script Executable
Suppose you have a shell script called:
backup.sh
Initially, you may not be able to execute it directly.
You can add execute permission with:
chmod +x backup.sh
Then execute it with:
./backup.sh
This is especially useful when working with deployment scripts, automation scripts, and server administration tasks.
Changing Directory Permissions
chmod can also be used with directories.
For example:
chmod 755 myfolder
You can use the recursive option to apply permissions to files and directories inside a folder:
chmod -R 755 myfolder
However, recursive permission changes should be used carefully.
Applying the same permission to every file and directory can create security or functionality problems. For example, regular files usually do not need execute permission.
What Does chmod -R Mean?
The -R option means recursive.
For example:
chmod -R 755 website/
This applies the permission change throughout the website directory and its contents.
Recursive commands are powerful, but they should be used cautiously, particularly on production servers.
Common chmod Examples
Give the owner full permissions
chmod 700 private.txt
Result:
rwx------
Give everyone read permission
chmod 444 file.txt
Result:
r--r--r--
Remove write permission from everyone
chmod a-w file.txt
Give the owner execute permission
chmod u+x script.sh
Give the group read and write permissions
chmod g+rw file.txt
Remove execute permission from others
chmod o-x script.sh
chmod and Security
Incorrect file permissions can create security vulnerabilities.
For example, giving every user write access to sensitive application files can allow unauthorized modifications.
Avoid using overly permissive settings such as:
chmod 777 file
unless there is a specific and well-understood reason.
777 gives read, write, and execute permissions to the owner, group, and everyone else. In many situations, this provides considerably more access than necessary.
A better approach is to follow the principle of least privilege: give users and applications only the permissions they actually need.
chmod vs chown
chmod and chown are related but perform different tasks.
chmod changes permissions:
chmod 755 app.sh
chown changes ownership:
chown user:user app.sh
In server administration, you may need both commands to correctly configure application files.
For example:
chown www-data:www-data website/
chmod 755 website/
The exact ownership and permission configuration should depend on the application's architecture and server environment.
Checking Permissions Before and After chmod
Use:
ls -l filename
to check the current permissions.
For example:
-rw-r--r-- 1 user user 1024 file.txt
After changing permissions:
chmod 755 file.txt
check again:
ls -l file.txt
This helps verify that the expected permissions were applied.
Common chmod Mistakes
Using 777 for Everything
Giving maximum permissions to everyone can expose applications and files unnecessarily.
Applying chmod -R Without Checking the Contents
Recursive permission changes can affect thousands of files and directories.
Confusing Permissions With Ownership
Changing permissions does not change the owner of a file. Use chown when ownership needs to change.
Giving Execute Permission to Every File
Not every file needs to be executable. Apply permissions according to the actual purpose of the file.
Changing Production Permissions Without Testing
Incorrect permissions can prevent web applications, services, scripts, or deployment processes from working correctly.
Best Practices for Using chmod
Follow these practices when managing Linux permissions:
Use the least permissions required.
Avoid chmod 777 unless absolutely necessary.
Check existing permissions before making changes.
Be careful with recursive commands.
Understand the difference between users, groups, and others.
Test permission changes in a development or staging environment when possible.
Use ls -l to verify the result.
Combine chmod with appropriate ownership management when required.
Pay particular attention to sensitive configuration and credential files.
Document permission changes on production systems.
Why chmod Is Important for Developers
Developers working with Linux servers frequently encounter permission-related issues.
For example, a deployment may fail because:
A script is not executable.
A web server cannot read a file.
An application cannot write to a required directory.
A log directory has incorrect permissions.
A deployment user does not have access to a required resource.
Understanding chmod makes it easier to diagnose and resolve these problems without unnecessarily giving broad permissions.
Linux remains an important platform for modern application hosting, cloud infrastructure, and server administration, making permission management an essential technical skill.
Conclusion
The Linux chmod command provides a simple but powerful way to control access to files and directories. By understanding read, write, and execute permissions along with users, groups, and others, developers and system administrators can manage Linux environments more securely.
Whether you are making a script executable, protecting sensitive files, configuring a web server, or managing application deployments, knowing how to use chmod correctly can help prevent both operational and security problems.
For modern software projects, proper server configuration and permission management should be considered part of the overall development and deployment process. Solace Infotech works on customized software development and scalable web and mobile solutions, with development teams supporting complex application and infrastructure requirements.