Credit: Sandra H-S Halloween has come and gone. In fact, so has Thanksgiving. But some masks are always appropriate – not because we’re trying to inspire people to give us candy, but because it’s just too easy to end up with file permissions that don’t reflect the security constraints that work best for us. To help with that, we Unix and Linux users have umask. The umask setting provides default permissions for any files or directories that you create. If you want that default behavior to ensure that only you can see the files you create, you use one setting. If you want all of your files to be shared by default with people in your core group, you use a different one. The process is easy and fairly straightforward except for one thing. You have to think in a way that may be a bit unusual. The umask setting is, after all, a mask and that implies that it works in a way that is opposite of the way settings normally work. Using a mask A 0 in your umask setting doesn’t mean that files you create will be set up with no permissions at all (i.e., with all permissions being denied). Instead, it means that all permissions will be assigned. When using a umask set to 000, for example, directories that you create will be set up with read, write, and execute permissions for everyone. Here’s an example of how it works: $ umask 000 $ mkdir open $ ls -ld open drwxrwxrwx 2 bugfarm techstaff 4096 Nov 29 12:34 open Setting umask to 000 and creating a directory, you end up with the same result as creating a directory and then setting its permissions to 777. Set your umask to 777 and you’ll get the opposite effect. Directories that you create will provide no permissions to anyone. $ umask 777 $ mkdir closed $ ls -ld closed d--------- 2 bugfarm techstaff 4096 Nov 29 12:45 closed Umask settings are generally not set to 000 or 777 as they’d leave our files too open or too closed. Let’s take a look at more common settings and how they work. Checking your umask You can use the umask command without arguments to display your current setting. $ umask 0007 The setting is usually configured by your shell’s main configuration file – such as /etc/bashrc which might have something like this: if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then umask 002 else umask 022 fi In this case, all users with UIDs of 200 and above (presumably user accounts rather than system accounts) will get a umask setting of 002 which means that those users and individuals in their primary group will be given the same permissions to files and directories, but that everyone else will have reduced permissions. The other thing that you may notice in this segment of code is that it’s checking whether the group and username are the same with the id -gn and id -un commands before using the 002 setting. So, the user and group settings are only the same if the user is in a group of his own. Your system may not be set up that way. And, of course, you can change your umask setting either interactively or by changing it within your personal shell startup file (e.g., ~/.bashrc). But what exactly do those 002 and 022 settings mean? The 002 setting indicates that the permissions we’ll assign to directories will be 775. The 022 setting means the permissions will be 755. If we think of these settings as binary numbers, every 1 becomes a 0 and every 0 becomes a 1. The table below shows how each digit is translated. The “Mask Value” settings in this table, such as 110 indicate the permissions that will be given (read and write, but not execute) for the particular owner, group member, or other. There is a difference, however, is how the umask is applied to files and directories. Since we don’t have a separate mask setting for each, we instead have a difference in how the setting is applied. The basic rule is: files are never given execute permission through the umask setting. If your umask setting is 770, directories you create will be set to rwxrwx—. Files, on the other hand, will only get rw-rw—-. You have to intentionally give the files execute permission with the chmoc command. They will not get it simply based on your umask setting. Related content how-to How to find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe