Linux Permission Basics
Understanding Linux File Permissions
In Linux systems, file permissions are a critical security mechanism that controls access to files and directories. Each file and directory has three types of permissions:
Permission Type |
Symbol |
Meaning |
Read |
r |
View file contents or list directory contents |
Write |
w |
Modify file or create/delete files in directory |
Execute |
x |
Run file as a program or access directory |
Permission Levels
Permissions are defined for three user levels:
graph TD
A[User Levels] --> B[Owner]
A --> C[Group]
A --> D[Others]
Viewing Permissions
Use the ls -l
command to view file permissions:
$ ls -l example.txt
-rw-r--r-- 1 username groupname 1024 May 10 12:00 example.txt
Permission Representation
Permissions are represented by a 9-character string:
- First 3 characters: Owner permissions
- Next 3 characters: Group permissions
- Last 3 characters: Others permissions
Numeric Permission Representation
Permissions can also be set using numeric values:
Value |
Permission |
4 |
Read |
2 |
Write |
1 |
Execute |
Example: chmod 755 script.sh
gives read, write, execute to owner, and read and execute to group and others.
Common Permission Commands
chmod
: Change file permissions
chown
: Change file ownership
chgrp
: Change file group
By understanding these basics, users can effectively manage file access in Linux systems with LabEx's comprehensive learning environment.