Understanding File Permissions
Linux security is heavily dependent on the permission system. Use the ls -l command to view permissions.
Permission Structure Example
-rwxr-xr-- 1 user group 1024 Jan 1 10:00 filename.txt
- File Type: (
-for file,dfor directory,lfor link). - Permissions (9 characters): Divided into three sets of three:
- Owner (u):
rwx(Read, Write, Execute) - Group (g):
r-x(Read, Execute) - Others (o):
r--(Read)
- Owner (u):
Changing Permissions (chmod)
We use chmod to change permissions, often using octal notation (r=4, w=2, x=1).
rwx= 4+2+1 = 7r-x= 4+0+1 = 5
Example: Granting the owner full control, group read/execute, and others only read:
bash chmod 754 filename.txt
Changing Ownership (chown)
Used to change the owner or group of a file:
bash
Change owner to 'alice'
chown alice filename.txt
Change owner and group to 'alice' and 'devs'
chown alice:devs filename.txt