Linux Basics 06 — File Permissions and umask

Linux course index · Linux Basics category · Lesson 6 of 8

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Read a permission string, predict umask results, and choose a minimal permission change.

Concepts and setup

Permissions are grouped into owner, group, and others. Read, write, and execute are 4, 2, and 1. A directory’s execute bit is search or traversal permission. Deleting a name normally depends on the parent directory’s permissions rather than the file’s write bit. A sticky directory can further restrict deletion.

The site’s 666 versus 777 example refers to the creation modes a program typically requests for regular files and directories. It is not a hard limit. umask clears requested bits. A parent default ACL can change creation-mode behavior, so use an ordinary lab filesystem for this drill.

Reproduce the umask example with fixed settings

lab=$(mktemp -d)
cd "$lab" || exit
( umask 022; touch file1.txt; mkdir dir1 )
stat -c '%a %A %n' file1.txt dir1
chmod g+w,o-r file1.txt
stat -c '%a %A %n' file1.txt
chmod 640 file1.txt
stat -c '%a %A %n' file1.txt

Possible output

644 -rw-r--r-- file1.txt
755 drwxr-xr-x dir1
660 -rw-rw---- file1.txt
640 -rw-r----- file1.txt

The subshell confines the changed umask. Numeric mode sets all three ordinary groups. A symbolic change can touch only the selected bits.

Apply a private creation mask

( umask 077; touch private.txt; mkdir private-dir )
stat -c '%a %n' private.txt private-dir

Possible output

600 private.txt
700 private-dir

For a shareable directory, choose group and traversal access deliberately rather than making it writable by everyone.

Questions only

Quick-check questions

  1. Why do ordinary new text files not execute by default?
  2. What does chmod g+w change?

Assessment questions

  1. Predict the default regular-file and directory modes for umask 027.
  2. Give the owner read/write and the group read access, with no access for others.
  3. Why might a directory with read but no execute permission list names but not let you open a named file?

Questions and answers

Quick-check answers

  1. Why do ordinary new text files not execute by default?
    Answer — The creating program normally requests 0666 rather than 0777.
  2. What does chmod g+w change?
    Answer — It adds write permission to the file’s group class without changing other bits.

Assessment answer key

  1. Predict the default regular-file and directory modes for umask 027.
    Answer — The usual results are 640 and 750 when there is no default ACL.
  2. Give the owner read/write and the group read access, with no access for others.
    Answer — chmod 640 file1.txt.
  3. Why might a directory with read but no execute permission list names but not let you open a named file?
    Answer — Reading lists names. Search permission is needed to traverse the directory and look up the named entry.

Source articles on this site

Continue the course

Previous lesson 05 — Finding Files and Filtering Text. Next lesson 07 — Processes, Jobs, and Signals.

Linux course index · Linux Basics category · Lesson 6 of 8

Leave a Reply