Linux File Permissions: Change Them Easily
In this article
Yes, you can change file and folder permissions on Linux using the chmod command (and chown for ownership). The quickest way is to open a terminal and run chmod with either symbolic (like u+x) or numeric (like 755) mode. This guide walks you through both methods, plus how to apply changes recursively and avoid common pitfalls.
What You'll Need
- A Linux system with a terminal (any distribution works).
- An account with sudo privileges if you need to change permissions on files you don't own.
- Basic familiarity with the command line (cd, ls).
Step-by-Step
- Open a terminal. On most desktops, press
Ctrl+Alt+Tor search for “Terminal” in the app menu. - Navigate to the directory containing the file or folder. Use
cdto move, e.g.,cd /home/username/Documents. Verify you’re in the right place withpwd. - Check current permissions. Run
ls -lto see a list like-rw-r--r--for files ordrwxr-xr-xfor directories. The first character indicates type (-file,ddirectory). The next nine characters are three groups of three: owner (u), group (g), and others (o). Each group hasr(read),w(write), andx(execute) permissions. - Use symbolic mode for simple changes. The syntax is
chmod [who][operator][permission] file. For example, to add execute permission for the owner on a script:chmod u+x script.sh. To remove write permission for others:chmod o-w file.txt. You can combine:chmod u+rwx,g+rx,o+r file. - Use numeric mode for precise control. Each permission has a value: read=4, write=2, execute=1. Add them for each group. For example,
chmod 755 filegives owner rwx (7), group r-x (5), others r-x (5). Common values: 644 (owner rw, group r, others r) for normal files, 755 for directories or executables. - Apply changes recursively to a folder and its contents. Add the
-Rflag:chmod -R 755 /path/to/folder. Be careful—this changes everything inside, including files that might need different permissions. - Change ownership if needed. Use
chownto change the owner and group. For example,sudo chown username:groupname file. To change only the group, usechgrp groupname file. - Verify the changes. Run
ls -lagain to confirm the new permissions appear correctly.
Common Mistakes
- Using uppercase X instead of lowercase x.
X(capital) only adds execute if the item is a directory or already has execute for some user. Stick to lowercasexunless you know you need the special behavior. - Forgetting the
-Rflag. If you runchmod 755 folderwithout-R, only the folder itself changes, not its contents. - Setting permissions too broadly. Using
chmod 777on a file gives everyone read, write, and execute—often a security risk. Use the least permissive setting that works. - Not using sudo when needed. If you get “Operation not permitted,” you likely need
sudobefore the command. - Confusing symbolic and numeric modes. Mixing them in one command (like
chmod 755 u+x) will fail. Use one or the other.
Tips
- Use
umaskto set default permissions. The umask determines default permissions for new files. For example,umask 022gives 644 for files and 755 for directories. Set it in your.bashrcto persist. - Test with a dummy file first. If you’re unsure, create a test file and practice on it before changing important data.
- Use
findfor selective changes. For example, to make all scripts executable in a folder:find . -name "*.sh" -exec chmod +x {} \; - Remember that directories need execute to be accessible. Without
xon a directory, you can’tcdinto it or list its contents. - Back up critical files before mass changes. A simple
cp -r folder folder.backupcan save you.
Troubleshooting
- “Operation not permitted” when changing permissions. This means you don’t own the file or lack sudo. Use
sudo chmod ...or ask the owner to change it. - Changes don’t seem to apply. Check if you’re looking at the right file (use
pwdandls -l). Also, if you’re on a filesystem that doesn’t support Unix permissions (like FAT32 or NTFS),chmodmay silently fail or have no effect. - You accidentally removed execute from a directory. If you can’t access a folder, run
sudo chmod u+x /path/to/folderto restore at least owner execute. - Recursive change messed up file permissions. If you set everything to 755 and now files are executable that shouldn’t be, run
chmod 644 filefor regular files, or usefindto target specific extensions. - Still stuck? Reboot or remount the filesystem if you suspect a caching issue. For network mounts, check the server’s permissions separately.
Frequently Asked Questions
What does chmod 755 mean?
It sets permissions to rwxr-xr-x: owner can read, write, execute; group and others can read and execute. It’s common for directories and executables.
How do I make a file executable?
Run chmod +x filename (adds execute for all) or chmod u+x filename (owner only).
What’s the difference between chmod and chown?
chmod changes permissions (read/write/execute), while chown changes ownership (which user and group own the file).
Can I change permissions on a file I don’t own?
Only if you have sudo privileges. Use sudo chmod ... to override ownership.
Why does my web server need specific permissions?
Web servers typically need read access to files and execute on directories. A common setting is 644 for files and 755 for directories, owned by your user.
How do I set permissions for a group?
First ensure the file’s group is correct with chgrp groupname file, then set group permissions with chmod g+rwx file or numeric like chmod 770 file.