الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

chmod

Change the permissions (mode) of files and directories, with numbers or letters.

المستوى
امتحان RHCSA
المجموعة
الصلاحيات
يحتاج root
للتغييرات
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Permissions are three groups of r w x: for the owner (u), the group (g) and others (o). Use numbers (chmod 750 dir, r = 4, w = 2, x = 1) or letters (chmod g+w,o-rwx dir).

A fourth digit in front sets the special bits: 4 = SUID, 2 = SGID, 1 = sticky. Only the owner of a file (or root) may change its mode.

طريقة الكتابة

chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...

الأجزاء الرئيسية

u g o a
Who: user (owner), group, others, all.
+ - =
Add, remove, set exactly.
r w x
Read, write, execute.
X
x only for directories and files that already have an x.
s
SUID (with u) or SGID (with g).
t
Sticky bit.
NNN / NNNN
Numbers: owner, group, others (and the special bits in front).

الخيارات 9

الأكثر استخدامًا

-R, --recursive
Change the whole tree.
-v, --verbose
Report every file.
-c, --changes
Report only changes.
-f, --silent, --quiet
Do not show most errors.
--reference=RFILE
Use the mode of RFILE.
--preserve-root
Refuse to work recursively on /.
--no-preserve-root
Do not treat / special (default).
--help
Show help.
--version
Show the version.

أمثلة 12

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1Make a script executable

    chmod +x backup.sh
    ./backup.sh

    +x = a+x (filtered by the umask).

  2. 2Normal file and private file

    chmod 644 index.html
    chmod 600 ~/.ssh/id_ed25519

    SSH refuses private keys that others can read.

  3. 3Team folder without access for others

    chmod 770 /srv/sales

    Owner and group full, others nothing.

  4. 4Shared folder with SGID and sticky

    chmod 3770 /srv/sales
    ls -ld /srv/sales
    drwxrws--T. 2 root sales 6 Oct 25 10:40 /srv/sales

    New files get the group; users delete only their own files.

  5. 5Add and remove in one command

    chmod g+w,o-rwx shared.txt

    Letters change only what you name.

  6. 6Give folders x but not files

    chmod -R u=rwX,g=rX,o= /srv/project

    Capital X: folders get x, normal files do not.

  7. 7Copy the mode of another file

    chmod --reference=index.html about.html

    Same permissions.

  8. 8Remove a dangerous SUID bit

    chmod u-s /usr/local/bin/oldtool

    SUID programs run as their owner — a big risk if the owner is root.

  9. 9Find world-writable files (security)

    find / -xdev -type f -perm -0002 -ls 2>/dev/null

    Anybody can change these files.

  10. 10Find SUID and SGID programs (security)

    find / -xdev -type f \( -perm -4000 -o -perm -2000 \) -ls 2>/dev/null

    Compare the list with a known good list.

  11. 11Protect a config with secrets

    chmod 640 /etc/myapp/db.conf; chgrp myapp /etc/myapp/db.conf

    The service group reads it; others cannot.

  12. 12See the mode as a number

    stat -c '%a %A %n' /etc/shadow /tmp
    0 ---------- /etc/shadow
    1777 drwxrwxrwt /tmp

    %a = number, %A = letters.

انتبه

  • chmod -R 777 is never a fix: it gives everybody full access.
  • chmod -R 644 dir removes the x from folders: nobody can enter them. Use X.
  • S or T in ls means the special bit without x (often a mistake, except on a folder with no access for others).

رموز الخروج

0 :: Done. 1 :: Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man chmod