Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

umask

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

Level
RHCSA exam
Group
Permissions
Needs root
No
Package
bash (built-in)

What it does

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.

How to write it

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

Options 3

Most used

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.

Examples 11

$ run as a normal user# run as root (or with 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.

Watch out

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

Files

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

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man umask