>_ IzzyLab

Hands-on task

This task is step 6 of the course “Users, groups and permissions”

Default permissions via umask

medium~5 min

The script /root/gen.sh creates report files in /srv/gd with touch, but they come out with permissions 644 — readable by everyone. Open the script in the Editor tab above the terminal and fix the script itself so the files it creates get exactly 640, by setting this through umask. Don't use chmod in the script.

What you'll practise:
  • umask
  • default permissions
  • chmod
  • octal permissions
  • touch

Topic breakdown

umask is a mask of permission bits that are cleared from newly created files and directories. For files the starting point is 666, for directories 777; every bit set in the mask is cleared in the resulting permissions (a bitwise "AND NOT", not arithmetic subtraction). So umask 027 leaves files at 640, and umask 033 at 644 (not 633). umask only affects creation: touch on an existing file doesn't change its permissions. Unlike chmod, which changes the permissions of an existing file, umask affects future creations within the current shell process, which is why it is set at the start of a script.

What's checked

  1. script uses umask
  2. script's files get 640

What it looks like