Linux file permissions and ownership are fundamental security mechanisms
← Back to Linux BasicsLinux file permissions and ownership are fundamental security mechanisms that control who can read, write, or execute files and directories.
Every file and directory in Linux has an owner and a group.
u):
The user who owns the file, usually its creator. The superuser (root)
can override all permission restrictions.
g):
A collection of users who share access permissions. This simplifies managing access
for teams (e.g., a developers group).
o):
All other users on the system who are neither the owner nor part of the group.
You can view ownership and permissions using:
ls -l filename
Example output:
drwxr-xr-- user group filename
The 5th column shows the owner and the 6th column shows the group.
Permissions are assigned to each ownership type (user, group, others) using three privileges: read, write, and execute.
| Permission | Symbol | Files | Directories |
|---|---|---|---|
| Read | r |
View file contents | List directory contents |
| Write | w |
Modify or delete the file | Create, delete, or rename files |
| Execute | x |
Run the file as a program or script | Enter (cd) the directory and access metadata |
chmod)You can use either symbolic notation or absolute (octal) mode.
Use u (user), g (group), o (others), or a (all),
along with + (add), - (remove), or = (set).
chmod u+x filename # Add execute permission for owner
chmod o-rw filename # Remove read & write for others
chmod a=rwx filename # Set full permissions for everyone
Each permission has a numeric value:
r = 4w = 2x = 1- = 0
rwx = 7
rw- = 6
r-x = 5
r-- = 4
--- = 0
chmod 755 filename # Owner: rwx, Group: r-x, Others: r-x
chmod 600 filename # Owner: rw-, Group: ---, Others: ---
chown & chgrp)These commands usually require sudo privileges.
sudo chown user:group filename # Change owner and group
sudo chown user filename # Change owner only
sudo chgrp group filename # Change group only