Permissions and Access
Understanding Linux Permissions
Permission Representation
graph LR
A[Permission Types] --> B[Read r]
A --> C[Write w]
A --> D[Execute x]
Permission Levels
Level |
Owner |
Group |
Others |
Read (r) |
4 |
4 |
4 |
Write (w) |
2 |
2 |
2 |
Execute (x) |
1 |
1 |
1 |
Viewing Permissions
## List detailed permissions
ls -l
## Example output
## -rw-r--r-- 1 user group 1024 May 15 10:30 file.txt
Changing Permissions
Numeric Method (chmod)
## Change to read, write for owner
chmod 600 file.txt
## Full read/write/execute for owner
chmod 700 directory
## Typical project directory permissions
chmod 755 project_folder
Symbolic Method
## Add execute permission for all
chmod +x script.sh
## Remove write permission for group
chmod g-w file.txt
## Set specific permissions
chmod u=rwx,g=rx,o=r file.txt
Ownership Management
## Change file owner
chown username:groupname file.txt
## Recursive ownership change
chown -R labex:developers project_folder
Advanced Permission Concepts
Special Permissions
graph TD
A[Special Permissions] --> B[SUID]
A --> C[SGID]
A --> D[Sticky Bit]
Special Permission Examples
## Set SUID (run with owner's permissions)
chmod u+s executable
## Set SGID (inherit group permissions)
chmod g+s directory
## Set Sticky Bit (prevent file deletion)
chmod +t shared_directory
Best Practices
- Follow principle of least privilege
- Regularly audit directory permissions
- Use groups for efficient permission management
- Be cautious with recursive permission changes
Common Permission Scenarios
Scenario |
Recommended Permissions |
Explanation |
Personal Project |
700 |
Full access for owner |
Shared Project |
750 |
Owner full, group read/execute |
Public Readable |
755 |
Owner full, others read/execute |
Security Considerations
- Avoid using 777 permissions
- Regularly check and update permissions
- Use access control lists for complex scenarios
- Implement LabEx security guidelines
Troubleshooting Permission Issues
## Check current permissions
id
## Verify file access
access file.txt
## Debug permission problems
ls -l file.txt