Linux File Permissions: A Practical Guide for Developers
Linux file permissions control who can read, modify, or execute files and who can traverse or modify directories. Understanding them is essential for development, deployment, and server administration.
Permission Classes
Permissions are defined for:
- user (
u) — the file owner; - group (
g) — users in the file’s group; - others (
o) — everyone else.
The basic permission bits are:
- read (
r); - write (
w); - execute (
x).
For directories, r allows listing names, w allows creating/removing entries when combined with appropriate access, and x allows traversal.
Inspect Permissions
ls -l file.txtExample:
-rwxr-xr-x 1 user group 4096 Aug 18 10:00 file.txtThe three rwx groups represent owner, group, and others.
Change Permissions with chmod
Symbolic mode:
chmod u+x script.sh
chmod g-w file.txt
chmod o= file.txtNumeric mode uses 4 for read, 2 for write, and 1 for execute:
chmod 755 script.sh # rwxr-xr-x
chmod 640 config # rw-r-----Avoid using 777 as a routine fix; granting write access to everyone usually creates unnecessary security risk.
Change Ownership
sudo chown alice file.txt
sudo chgrp dev_team file.txt
sudo chown alice:dev_team file.txtUse recursive ownership changes carefully:
sudo chown -R alice:dev_team /path/to/projectVerify the target path first because a recursive command can affect many files quickly.
Make a Script Executable
chmod u+x script.sh
./script.shThe script should also have an appropriate shebang, such as:
#!/usr/bin/env bashConclusion
Use ls -l to inspect permissions, chmod to change access bits, and chown/chgrp to manage ownership. Grant only the permissions an application or user actually needs, especially on shared or production systems.