Permission Management
Changing File Permissions
Using chmod
Command
graph LR
A[chmod Modes] --> B[Symbolic Mode]
A --> C[Numeric Mode]
Symbolic Mode
## Add execute permission for user
chmod u+x file.txt
## Remove write permission for group
chmod g-w file.txt
## Set full permissions
chmod u=rwx,g=rx,o=r file.txt
Numeric Mode
## Set permissions to 755
chmod 755 file.txt
## Breakdown of 755
## 7 (User): read + write + execute
## 5 (Group): read + execute
## 5 (Others): read + execute
Changing File Ownership
chown
Command
## Change file owner
chown username file.txt
## Change owner and group
chown username:groupname file.txt
Permission Management Strategies
Strategy |
Description |
Example |
Least Privilege |
Minimal necessary permissions |
chmod 640 sensitive.txt |
Group Management |
Use groups for access control |
chgrp developers project/ |
Regular Audits |
Periodically check permissions |
find / -perm /4000 |
Special Permissions
Setuid, Setgid, and Sticky Bit
graph TD
A[Special Permissions] --> B[Setuid: u+s]
A --> C[Setgid: g+s]
A --> D[Sticky Bit: o+t]
Examples
## Set setuid
chmod u+s script.sh
## Set setgid
chmod g+s directory/
## Set sticky bit
chmod o+t /tmp
Best Practices
- Avoid using
chmod 777
- Use group permissions effectively
- Regularly review and update permissions
LabEx Practical Learning
In the LabEx Linux environment, students can practice permission management through interactive exercises, gaining real-world system administration skills.