AI Hints
Home›Linux Tutorial›Permissions Practice
Linux · Lesson 74 of 120

Default Permissions

Umask.

⏱ 2 min read▶ Video at 1:37:37🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

When you create a new file, it gets permissions straight away. RW, R, R. Where does that come from? A setting called the U mask.

Default Permissions
From the video: Default Permissions
  • New files get permissions
  • rw-r--r--
  • Where from? The umask

Seeing the mask

U mask prints the current mask. Zero zero two two. Think of it as the permissions to take away. New files start from six six six, take away zero two two, and end up as six four four. Folders start from seven seven seven, and end up as seven five five.

Terminal
umask
0022
touch new.txt && mkdir newdir
ls -ld new.txt newdir
-rw-r--r-- 1 sam sam    0 Jan  5 09:00 new.txt
drwxr-xr-x 2 sam sam 4096 Jan  5 09:00 newdir

A stricter mask

Set the mask to zero seven seven, and new files are private from the start. Six hundred for files, seven hundred for folders. This only lasts for the current terminal. To keep it, you'd put the U mask command in your dot bash RC file.

Terminal
umask 077
touch private.txt && mkdir privdir
ls -ld private.txt privdir
-rw------- 1 sam sam    0 Jan  5 09:00 private.txt
drwx------ 2 sam sam 4096 Jan  5 09:00 privdir

Why files never get X by default

Notice new files never get execute permission, even with the friendliest mask. That's deliberate. Linux won't let a new file be run as a program, until someone decides it should, with CH mod plus X. It's one more small safety net.

keyvalue
Files start at666, never x
Folders start at777
umask 022644 / 755
umask 077600 / 700

Summary

The U mask takes permissions away from new files and folders. Zero two two gives six four four and seven five five. Next, a quick permissions quiz.

Key takeaways
  • umask
  • 022 → 644 / 755
  • 077 → 600 / 700
Next up: Permissions Quiz — test yourself