Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

umask

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

Niveau
RHCSA-examen
Groep
Rechten
Root nodig
Nee
Pakket
bash (built-in)

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

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

Opties 3

Meest gebruikt

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.

Voorbeelden 11

$ als gewone gebruiker# als root (of met 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.

Let op

  • 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.

Bestanden

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

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man umask