توضیح دقیق و فنی به زبان فارسی و انگلیسی — نمایش نمادین، نمایش عددی، بیتهای ویژه و مثالها
Detailed and technical explanation in Persian and English — Symbolic notation, octal representation, special bits, and examples
هر فایل یا دایرکتوری در لینوکس دارای Permission bits است که مشخص میکند چه کسی میتواند:
Every file or directory in Linux has permission bits that determine who can:
و اینها برای سه گروه تنظیم میشوند:
These are set for three groups:
| گروه Group | توضیح Description |
|---|---|
| Owner (u) | صاحب فایل File owner |
| Group (g) | اعضای گروه فایل Members of the file’s group |
| Others (o) | سایر کاربران سیستم Other system users |
وقتی از دستور ls -l استفاده میکنید، مثلاً خروجی زیر را میبینید:
When you use the ls -l command, you might see output like this:
-rwxr-xr--
تجزیهٔ این نمایش به شکل زیر است:
This notation breaks down as follows:
| بخش Part | معنا Meaning |
|---|---|
- | نوع فایل (خط تیره یعنی فایل معمولی، d یعنی دایرکتوری)File type (dash means regular file, d means directory) |
rwx | دسترسی owner Owner permissions |
r-x | دسترسی group Group permissions |
r-- | دسترسی others Others permissions |
هر مجموعه از سه بیت (r, w, x) به صورت دودویی کدگذاری میشود:
Each set of three bits (r, w, x) is encoded in binary:
| حرف Symbol | بیت دودویی Binary Bit | مقدار عددی Numeric Value |
|---|---|---|
r | 100 | 4 |
w | 010 | 2 |
x | 001 | 1 |
برای هر گروه (Owner, Group, Others):
For each group (Owner, Group, Others):
rwx = 7rw- = 6r-x = 5r-- = 4--- = 0مثال:
Example:
-rwxr-xr--
که به صورت عددی میشود:
Which translates to:
Owner: rwx = 7
Group: r-x = 5
Others: r-- = 4
→ Permission code = 754
و در عمل:
In practice:
chmod 754 filename
علاوه بر ۹ بیت اصلی، ۳ بیت ویژه هم وجود دارد:
In addition to the 9 main bits, there are 3 special bits:
| بیت Bit | نام Name | مقدار Value | توضیح Description |
|---|---|---|---|
| SUID | Set user ID | 4 | اجرای فایل با سطح دسترسی صاحب فایل Execute file with owner’s permissions |
| SGID | Set group ID | 2 | اجرای فایل با سطح دسترسی گروه فایل Execute file with group’s permissions |
| Sticky bit | Sticky | 1 | فقط صاحب فایل میتواند آن را حذف کند (برای دایرکتوریها مثل /tmp)Only the owner can delete (used for directories like /tmp) |
اگر یکی از اینها فعال باشد، یک رقم به ابتدای عدد اضافه میشود. مثلاً:
If one of these is active, a digit is added to the start of the number. For example:
chmod 4755 # Enable SUID with standard 755 permissions
chmod 1777 # Enable Sticky bit (e.g., for /tmp)
در سطح پایینتر، تمام مجوزها (permissions) در لینوکس به صورت ۱۲ بیت دودویی (binary) ذخیره میشوند. این بیتها به چهار گروه تقسیم میشوند:
At a lower level, all permissions in Linux are stored as 12 binary bits. These bits are divided into four groups:
r, w, x)r, w, x)r, w, x)r, w, x)r, w, x)r, w, x)هر بیت نشاندهنده یک مجوز است: ۱ به معنای فعال (مجوز دادهشده) و ۰ به معنای غیرفعال. برای مثال، مجوز rwx به صورت دودویی 111 است (r=4=100, w=2=010, x=1=001 که جمعشان 7=111 میشود).
Each bit represents a permission: 1 means enabled (permission granted), 0 means disabled. For example, rwx in binary is 111 (r=4=100, w=2=010, x=1=001, summing to 7=111).
برای تبدیل نمایش نمادین به دودویی، هر حرف را به بیت مربوطه تبدیل کنید:
To convert symbolic notation to binary, map each letter to its bit:
| نمادین Symbolic | بیتها Bits | توضیح Explanation |
|---|---|---|
r | 100 | بیت خواندن (read bit) |
w | 010 | بیت نوشتن (write bit) |
x | 001 | بیت اجرا (execute bit) |
- | 000 | بدون مجوز (no permission) |
مثال کامل برای -rwxr-xr-- بدون بیتهای ویژه (یعنی بیتهای ۱–۳ برابر ۰۰۰):
Full example for -rwxr-xr-- without special bits (bits 1–3 as 000):
| گروه Group | نمادین Symbolic | دودویی Binary | عددی (Octal) Octal |
|---|---|---|---|
| ویژه Special | --- | 000 | 0 |
| صاحب Owner | rwx | 111 | 7 |
| گروه Group | r-x | 101 | 5 |
| دیگران Others | r-- | 100 | 4 |
بیتهای کامل: 000 111 101 100 که به octal تبدیل میشود: 0754 (بیت ویژه ۰ اضافه میشود).
Full bits: 000 111 101 100, which converts to octal: 0754 (leading 0 for special bits).
اگر بیت ویژهای فعال باشد، مثلاً SUID (بیت ۱=۱، یعنی ۱۰۰ در دودویی = ۴ در octal)، بیتها تغییر میکنند. مثلاً برای 4755: بیت ویژه ۱۰۰ (۴)، صاحب ۱۱۱ (۷)، گروه ۱۰۱ (۵)، دیگران ۱۰۱ (۵).
If a special bit is active, e.g., SUID (bit 1=1, binary 100 = octal 4), the bits change. For 4755: special 100 (4), owner 111 (7), group 101 (5), others 101 (5).
-rwxr-xr--
↓
000 111 101 100 (binary for standard 754)
= 0754 (octal, with leading 0 often omitted)
چند دستور پرکاربرد برای مدیریت Permission:
Some common commands for managing permissions:
chmod u+x file: افزودن دسترسی اجرا برای صاحب فایلchmod g-w file: حذف دسترسی نوشتن برای گروهchmod o=r file: تنظیم دسترسی فقط خواندن برای دیگرانchown user file: تغییر صاحب فایلchgrp group file: تغییر گروه فایلاسکریپت شل برای تحلیل Permission فایل:
Shell script to analyze file permissions:
#!/bin/bash
file=$1
if [ -e "$file" ]; then
perms=$(ls -l "$file" | cut -c 1-10)
echo "File: $file"
echo "Permissions: $perms"
echo "Owner: ${perms:1:3}"
echo "Group: ${perms:4:3}"
echo "Others: ${perms:7:3}"
octal=$(stat -c %a "$file")
echo "Octal: $octal"
else
echo "File not found!"
fi
ذخیره کنید به نام check_perms.sh و اجرا کنید:
Save as check_perms.sh and run:
chmod +x check_perms.sh && ./check_perms.sh filename
| سطح Level | دسترسی Permission | مقدار عددی Description |
|---|---|---|
| 777 | rwxrwxrwx | همه دسترسی دارند Full access for all |
| 755 | rwxr-xr-x | فقط owner کامل Full access for owner only |
| 700 | rwx------ | فقط owner دسترسی دارد Access for owner only |
| 644 | rw-r--r-- | برای فایلهای عمومی For public files |
| 600 | rw------- | فایلهای خصوصی (مثل SSH key) Private files (e.g., SSH keys) |