File Permissions in Linux — How They Are Encoded

توضیح دقیق و فنی به زبان فارسی و انگلیسی — نمایش نمادین، نمایش عددی، بیت‌های ویژه و مثال‌ها
Detailed and technical explanation in Persian and English — Symbolic notation, octal representation, special bits, and examples

۱. ساختار کلی Permission در لینوکس
1. General Structure of Permissions in Linux

هر فایل یا دایرکتوری در لینوکس دارای 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

۲. نمایش نمادین (Symbolic)
2. Symbolic Notation

وقتی از دستور 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

۳. نمایش عددی (Octal Representation)
3. Octal Representation

هر مجموعه از سه بیت (r, w, x) به صورت دودویی کدگذاری می‌شود:
Each set of three bits (r, w, x) is encoded in binary:

حرف
Symbol
بیت دودویی
Binary Bit
مقدار عددی
Numeric Value
r1004
w0102
x0011

برای هر گروه (Owner, Group, Others):
For each group (Owner, Group, Others):

مثال:
Example:

-rwxr-xr--

که به صورت عددی می‌شود:
Which translates to:


Owner: rwx = 7
Group: r-x = 5
Others: r-- = 4
→ Permission code = 754
      

و در عمل:
In practice:

chmod 754 filename

۴. بیت‌های ویژه (Special Bits)
4. Special Bits

علاوه بر ۹ بیت اصلی، ۳ بیت ویژه هم وجود دارد:
In addition to the 9 main bits, there are 3 special bits:

بیت
Bit
نام
Name
مقدار
Value
توضیح
Description
SUIDSet user ID4اجرای فایل با سطح دسترسی صاحب فایل
Execute file with owner’s permissions
SGIDSet group ID2اجرای فایل با سطح دسترسی گروه فایل
Execute file with group’s permissions
Sticky bitSticky1فقط صاحب فایل می‌تواند آن را حذف کند (برای دایرکتوری‌ها مثل /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)
      

۵. ترکیب دودویی (Binary Encoding)
5. Binary Encoding

در سطح پایین‌تر، تمام مجوزها (permissions) در لینوکس به صورت ۱۲ بیت دودویی (binary) ذخیره می‌شوند. این بیت‌ها به چهار گروه تقسیم می‌شوند:
At a lower level, all permissions in Linux are stored as 12 binary bits. These bits are divided into four groups:

هر بیت نشان‌دهنده یک مجوز است: ۱ به معنای فعال (مجوز داده‌شده) و ۰ به معنای غیرفعال. برای مثال، مجوز 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
r100بیت خواندن (read bit)
w010بیت نوشتن (write bit)
x001بیت اجرا (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
---0000
صاحب
Owner
rwx1117
گروه
Group
r-x1015
دیگران
Others
r--1004

بیت‌های کامل: 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
6. Practical Commands for Managing Permissions

چند دستور پرکاربرد برای مدیریت Permission:
Some common commands for managing permissions:

اسکریپت شل برای تحلیل 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

۷. خلاصه سریع
7. Quick Summary

سطح
Level
دسترسی
Permission
مقدار عددی
Description
777rwxrwxrwxهمه دسترسی دارند
Full access for all
755rwxr-xr-xفقط owner کامل
Full access for owner only
700rwx------فقط owner دسترسی دارد
Access for owner only
644rw-r--r--برای فایل‌های عمومی
For public files
600rw-------فایل‌های خصوصی (مثل SSH key)
Private files (e.g., SSH keys)
برای دانلود این صفحه به‌صورت PDF یا فایل HTML کامل، بگویید تا لینک فراهم کنم.
Let me know if you need a PDF or full HTML file download link.