Chmod vs. Chown in Linux: What's the Difference and When to Use Each?
Learn the key differences between chmod and chown in Linux, two commands that control different aspects of file security. We'll explain when to use each one and how they work together to protect your system.
If you've spent any time managing a Linux server, you've probably run into permission errors. Maybe a script won't execute, a web server can't read a config file, or a user can't access a directory they should be able to. These problems usually come down to two commands: chmod and chown.
While they both deal with file security, they serve completely different purposes. Understanding when to use each one (and how they work together) is one of those foundational skills that makes server management much smoother.
What's the difference between chmod and chown?
Here's the short version: chmod changes what users can do with a file, while chown changes who owns the file in the first place.
Think of it like a house. The owner (set by chown) has the keys and decides who gets access. The permissions (set by chmod) are like locks on different doors, controlling whether someone can enter, look around, or make changes.
Linux tracks three types of access for every file and directory:
Owner: The user who owns the file
Group: A collection of users who share certain permissions
Others: Everyone else on the system
Each of these categories can have read, write, and execute permissions. That's where chmod comes in.
How chmod works
The chmod command modifies file permissions. You can think of it as setting the rules for who can read, write, or execute a file.
There are two ways to use chmod: symbolic mode and numeric (octal) mode.
Symbolic mode
Symbolic mode uses letters to represent permissions:
r = read
w = write
x = execute
You combine these with:
u = user (owner)
g = group
o = others
a = all
For example, to give the owner execute permission on a script:
chmod u+x script.sh
To remove write access for others:
chmod o-w myfile.txt
Numeric mode
Numeric mode uses three digits, one for each category (owner, group, others). Each digit is the sum of:
4 = read
2 = write
1 = execute
So chmod 755 means:
Owner: 7 (4+2+1 = read, write, execute)
Group: 5 (4+1 = read, execute)
Others: 5 (4+1 = read, execute)
This is commonly used for web directories. The owner can do everything, while the group and others can read and navigate but not modify files.
Another common permission is 644:
chmod644 index.html
This gives the owner read and write access (4+2), while the group and others can only read (4).
You'll see chmod 600 for sensitive files like SSH keys, which only the owner should access:
chmod600 ~/.ssh/id_rsa
How chown works
While chmod controls permissions, chown changes file ownership. The syntax is straightforward:
chown username filename
You can also change the group at the same time:
chown username:groupname filename
Or just the group:
chown :groupname filename
Let's say you've installed a web application and the files are owned by root, but your web server runs as the www-data user. The server won't be able to read the files. You'd fix this with:
chown www-data:www-data /var/www/html -R
The -R flag applies the change recursively to all files and subdirectories.
Sometimes you only need to change the group. For example, if you want multiple users in the developers group to access a project:
chown :developers /home/projects/myapp -R
When to use chmod vs. chown
Use chown when you need to transfer ownership of files. This happens when:
Setting up a new application or service
Fixing ownership after copying files as root
Giving a different user control over certain files
Configuring web servers or databases
Use chmod when you need to adjust what different users can do with files. Common scenarios include:
Making a script executable
Restricting access to configuration files
Setting up proper web directory permissions
Securing private keys or credentials
Often you'll need both. When deploying a web application, you might set ownership with chown to make sure the web server user owns the files, then use chmod to set appropriate read/write/execute permissions.
For instance, deploying a PHP application typically looks like this:
This gives ownership to the web server, allows it to navigate directories, and lets it read (but not modify) the PHP files.
Common permission patterns
Some permission sets come up again and again:
755 - Standard for directories and executable scripts. Owner can modify, everyone can read and execute.
644 - Standard for regular files. Owner can edit, everyone can read.
600 - Private files like SSH keys. Only the owner can access.
700 - Private directories. Only the owner can access.
775 - Shared directories where a group needs write access.
666 - Rarely used, but allows everyone to read and write (dangerous for most files).
You can check current permissions with ls -l:
ls-l myfile.txt
-rw-r--r-- 1 user group 1234 Dec 310:00 myfile.txt
The first column shows permissions (rw-r--r--), followed by the owner (user) and group (group).
Special permissions and advanced usage
Beyond basic read/write/execute, Linux has a few special permission bits worth knowing about.
The setuid bit
When set on an executable, the program runs with the permissions of the file's owner rather than the user who launched it. This is represented by an s in the owner's execute position:
chmod u+s /usr/bin/someprogram
Or numerically as 4755. The leading 4 sets the setuid bit.
The setgid bit
Similar to setuid but for groups. When set on a directory, new files created inside inherit the directory's group rather than the creator's default group:
chmod g+s /shared/project
Or 2755 numerically.
The sticky bit
Usually applied to shared directories. When set, only the file owner can delete or rename files in that directory, even if others have write access. The /tmp directory uses this:
chmod +t /shared/uploads
Or 1755 numerically.
Security considerations
Bad permissions are one of the most common security issues on Linux servers. A few guidelines:
Never use 777 unless you absolutely have to (and you probably don't). This gives everyone full access, which is almost never appropriate.
Be careful with chown on system files. Changing ownership of critical system files can break your system or create security holes.
Use the principle of least privilege. Give users and processes only the minimum permissions they need to function.
Watch out for world-writable files. If you see w in the "others" column of ls -l, think twice about whether that's necessary.
Configuration files with passwords or API keys should be 600 or 640 at most, owned by the user that needs them.
When running web applications, separate the web server user from the file owner when possible. This limits damage if the application is compromised.
Troubleshooting permission issues
When something doesn't work, permission problems are often the culprit. Start by checking ownership and permissions:
ls-la /path/to/problem/file
If a script won't execute, make sure it has the execute bit set:
chmod +x script.sh
If a service can't read its config file, check both ownership and permissions:
Parent directory permissions matter too. Even if a file has proper permissions, you can't access it if you don't have execute permission on the directories leading to it.
SELinux or AppArmor can also block access even when standard permissions look correct. Check system logs if you've verified permissions and still have issues.
Frequently asked questions about chmod and chown
What happens if I use chmod 777 on everything?
While chmod 777 might seem like an easy fix for permission errors, it creates major security risks by giving all users full read, write, and execute access to your files. It's particularly dangerous on web servers where it could allow attackers to modify or execute files. Instead, identify exactly which user or group needs access and set minimum permissions like 755 for directories or 644 for files.
Can I change permissions on files I don't own?
Only the file owner and root can modify permissions with chmod. Regular users can't change permissions on files they don't own, even if they have read or write access. If you need to modify permissions on files owned by another user, you'll need root access or ask the owner to make the changes.
Why does my SSH key give a "permissions are too open" error?
SSH requires private keys to have strict permissions for security. If your key file is readable by other users, SSH refuses to use it. Fix this with chmod 600 ~/.ssh/id_rsa to restrict access to only the owner. This is a safety feature that prevents others from copying your private key.
What's the difference between chown user:group and chown user.group?
Both syntaxes work identically in modern Linux systems. The colon (:) is the standard separator, while the dot (.) is an older notation that's still supported. However, the colon is recommended because usernames can contain dots, which could cause ambiguity with the dot syntax. Stick with chown user:group for clarity.
Do chmod permissions work the same way on all Linux distributions?
Yes, basic chmod and chown functionality works identically across all Linux distributions since they follow the POSIX standard. However, some distributions may have additional security layers like SELinux (on RHEL-based systems like AlmaLinux or Rocky Linux) or AppArmor (on Debian and Ubuntu) that can enforce additional access controls beyond standard file permissions.
Conclusion
Understanding chmod and chown is one of those skills that pays dividends every time you work with a Linux system. Whether you're deploying applications, troubleshooting access issues, or hardening security, knowing when to change ownership versus when to adjust permissions makes everything easier.
Start with conservative permissions and loosen them only when necessary. It's much better to deal with a "permission denied" error than to accidentally expose sensitive data or give malicious code an easy path to execution.