Managing file and directory permissions is essential for securing a Linux system. Every file and folder has defined permissions that control who can read, write, or execute it. This guide provides a clear, structured breakdown of how to inspect and modify these permissions using the terminal.
In Linux, each file and directory has three permission categories and three basic types of permissions:
To check permissions of files and directories, use:
bash
CopyEdit
ls -l
This command lists files with their permissions in the format:
bash
CopyEdit
-rw-r--r-- 1 user group 1234 May 22 20:00 example.txt
Explanation of this output:
Linux uses the chmod command to modify permissions. There are two methods:
Symbolic mode uses letters and operators to represent permission changes.
Syntax:
bash
CopyEdit
chmod [user category][operator][permission] [file/directory]
User Categories:
Operators:
Remove write permission from user:
bash
CopyEdit
chmod u-w file.txt
Add execute permission to group:
bash
CopyEdit
chmod g+x script.sh
Give read/write to all users:
bash
CopyEdit
chmod a=rw shared.txt
Each permission is represented numerically:
Permission
Value
Read (r)
4
Write (w)
2
Execute (x)
1
You add the values to get a single digit for each category.
Syntax:
bash
CopyEdit
chmod [three-digit number] [file/directory]
Set rw-r--r-- (user: read/write, group & others: read):
bash
CopyEdit
chmod 644 file.txt
Set rwxr-xr-x (user: all, group & others: read/execute):
bash
CopyEdit
chmod 755 program.sh
Set rwx------ (user: all, no access for others):
bash
CopyEdit
chmod 700 private.txt
Directories require execute (x) permission to be accessible. Use chmod the same way as for files.
Give user execute permission on a directory:
bash
CopyEdit
chmod u+x my_folder
Remove write permission from others:
bash
CopyEdit
chmod o-w my_folder
Apply changes recursively to all subdirectories and files:
bash
CopyEdit
chmod -R 755 /var/www
You can combine multiple symbolic permission changes in one command.
Add read for group, remove execute from others:
bash
CopyEdit
chmod g+r,o-x data.txt
Beyond standard permissions, Linux supports special bits for advanced use:
bash
CopyEdit
chmod u+s /usr/bin/special_program
bash
CopyEdit
chmod g+s /projects/team_dir
bash
CopyEdit
chmod +t /shared_folder
By mastering permission management with chmod, you can protect sensitive files, manage access, and maintain control over your Linux environment with precision and confidence.
If you’re still having trouble, consider reaching out to Support.Com for a personalized solution to all technical support issues.