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 news Supermicro unveils AI-optimized storage powered by Nvidia New storage system features multiple Nvidia GPUs for high-speed throughput. By Andy Patrizio Oct 24, 2024 3 mins Enterprise Storage Data Center news Nvidia to power India’s AI factories with tens of thousands of AI chips India’s cloud providers and server manufacturers plan to boost Nvidia GPU deployment nearly tenfold by the year’s end compared to 18 months ago. By Prasanth Aby Thomas Oct 24, 2024 5 mins GPUs Artificial Intelligence Data Center news Gartner: 13 AI insights for enterprise IT Costs, security, management and employee impact are among the core AI challenges that enterprises face. By Michael Cooney Oct 23, 2024 6 mins Generative AI Careers Data Center news Network jobs watch: Hiring, skills and certification trends What IT leaders need to know about expanding responsibilities, new titles and hot skills for network professionals and I&O teams. By Denise Dubie Oct 23, 2024 33 mins Careers Data Center Networking PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe