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

umask

Show or set the mask that decides the permissions of new files and directories.

المستوى
امتحان RHCSA
المجموعة
الصلاحيات
يحتاج root
لا
الحزمة
bash (built-in)

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

ماذا يفعل

Programs create new files with 666 (rw for all) and new directories with 777. The umask removes bits from this: with umask 022, files get 644 and directories 755.

umask is a shell built-in: it changes only the current shell and its children. Make it permanent in ~/.bashrc (one user) or a file in /etc/profile.d/ (all users). Services use the UMask= setting in their systemd unit.

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

umask [-p] [-S] [MODE]

الخيارات 3

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

MODE
The new mask, as a number (027) or in letters (u=rwx,g=rx,o=).
-S
Show the mask in letters (as the permissions that stay).
-p
Show it in a form you can use again as a command.

أمثلة 11

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

  1. 1Show the mask

    umask
    0022

    The RHEL default.

  2. 2Show it in letters

    umask -S
    u=rwx,g=rx,o=rx

    The rights that new directories get.

  3. 3Set a safer mask for this shell

    umask 027
    touch f; mkdir d; ls -ld f d
    -rw-r-----. 1 student student 0 Oct 25 10:30 f
    drwxr-x---. 2 student student 6 Oct 25 10:30 d

    Others get nothing.

  4. 4Make it permanent for one user

    echo "umask 027" >> ~/.bashrc

    Valid from the next shell.

  5. 5Make it permanent for all users

    echo "umask 027" > /etc/profile.d/umask.sh

    Read at every login shell.

  6. 6Very private files

    umask 077

    Files 600, folders 700.

  7. 7Set the umask with letters

    umask u=rwx,g=rx,o=
    umask
    0027

    Same as 027.

  8. 8Use a mask for one command only

    (umask 077; openssl genrsa -out private.key 4096)

    The key file is private from the start (no time window).

  9. 9Set the umask of a service

    systemctl edit myapp

    Add [Service] and UMask=0027 — shell files do not affect services.

  10. 10Check the default of new users

    grep -E '^(UMASK|HOME_MODE)' /etc/login.defs
    UMASK		022
    HOME_MODE	0700

    login.defs sets the umask for login and the mode of new home folders.

  11. 11Why a file never gets x from the umask

    umask 000; touch x; ls -l x
    -rw-rw-rw-. 1 student student 0 Oct 25 10:35 x

    Files start at 666; add x with chmod.

انتبه

  • The umask is not a chmod: it only affects files created later.
  • A default ACL on a directory replaces the umask for new files in it.

الملفات

~/.bashrc
umask for one user.
/etc/profile.d/*.sh
umask for all login shells.
/etc/login.defs
UMASK and HOME_MODE.

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

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

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