# Taking Control Of Default Permissions With Umask

> In this blog post, we will discuss the umask command from what it is to how to use it to set a custom umask.

- Author: [CJ Saathoff](https://www.namehero.com/blog/author/cj-saathoff/)
- Published: 2024-07-10
- Updated: 2024-07-10
- Category: [Linux Command Line](https://www.namehero.com/blog/category/linux-command-line/)
- Web page: https://www.namehero.com/blog/taking-control-of-default-permissions-with-umask/

[![](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/05/24082018/takingcontrol-1024x576.jpg)](https://blogcdn.namehero.com/blog/wp-content/uploads/2024/05/24082018/takingcontrol.jpg)

On Unix-like operating systems like Linux, the operating system consists of files and folders. With everything coming back to files and folders, permissions are important. Permissions for newly created files are just as important. Think about it, you don’t want to be constantly thinking about file permissions, and nor should you or your users. That is where umask comes into play, it allows for a safe default to be configured. In this blog post, we will discuss the umask command from what it is to how to use it to set a custom umask.

## What Is Umask?

The umask command is a utility that is used to control the initial file permissions for newly created files and directories.

## What Is The Difference Between Chmod And Umask?

Chmod changes permissions after a file or directory is created. Umask sets the default permission for files and directories before they are created to be applied as they are created.

## How To Calculate Umask Values

The initial mask value is calculated by subtracting the umask value from the default value, which is 777 for directories and 666 for files (because files are never created with execute permissions).

So for example, if we have a umask of 022 (which is the default on many systems) the resulting permissions would be 755 for directories and 644 for files.

Note: Sometimes a umask will have four digits, e.g. 0022. The first 0 is for the setuid, setgid, and sticky bits.

## Umask Values

Here are the values, keep in mind that these are being subtracted so a 2 would be removing write permissions.

1. or — Which means no permission change
2. or –x Which means removing the execute permission
3. or -w- Meaning remove write permission
4. or -wx Meaning remove write and execute permissions
5. or r– Which means remove read permission
6. or r-x To remove read and execute permissions
7. or rw- To remove Read and write permissions
8. or rwx To remove all three Read, write, and execute

### Are There Other Ways To Get The Umask?

Here are two websites I found that allows you to calculate the umask without needing to do that math.

- [https://www.heuristic42.com/tools/unixperms/](https://www.heuristic42.com/tools/unixperms/)
- [https://wintelguy.com/umask-calc.pl](https://wintelguy.com/umask-calc.pl)

## How To Find The Current Umask Value?

To find your calculated umask in octal notation run the following:

```

umask

```
 ![Results of running umask command](https://images.surferseo.art/eb7dfadf-f59b-4154-9bf7-48e01a0001b4.png)

To See umask in Symbolic notation value run:

```

umask -S

```
 ![Results of running umask -S command](https://images.surferseo.art/67277d2a-8117-455d-9c7b-037a62799583.png)

## How Do I Set A Custom Mask?

In this section, we have a few different ways that umask can be set.

Feel free to use your preferred value, Octal or Symbolic.

### Temporally Set Umask For One User

To temporally set a custom umask all you have to do is run the umask command with the mask value after it as shown below.

```

umask [mask_value]

```

This will take effect immediately but will only affect the current session.

### Permanently Set Umask For One User

To change your default permissions for a single user we take the same command but add it to the user’s ~/.bashrc file.

```

echo "umask [mask_value]" >> ~/.bashrc

```

Make sure to replace [mask_value]

Be aware that this will only apply on the next login, see the Temporally Set Umask section if you want to apply before for a user.

### Permanently Set Umask For All Users

To permanently override the default umask create a file at /etc/profile.d/umask.sh.

```

sudo echo "umask [mask_value]" > /etc/profile.d/umask.sh.

```

Make sure to replace [mask_value]

Be aware that this will only apply on the next login, see the Temporally Set Umask section if you want to apply before for a user.

## Conclusion

In this post, we started by answering what is umask and how it differs from the chmod command. Moved on to how to calculate umask values, what the values mean, and how to get the current mask value. Finally, we wrap things up with how to set a custom mask.

## Additional Links

Done reading and looking for additional webpages to read, why not check these out?

- [Other Chmod Posts](https://www.namehero.com/blog/?s=chmod)
- [Other Chown Posts](https://www.namehero.com/blog/?s=chown)
- [Arch Linux Wiki Umask](https://wiki.archlinux.org/title/Umask)
- [Wikipedia Umask](https://en.wikipedia.org/wiki/Umask)

## Related posts

- [Curl Headers, Cookies, and Authentication](https://www.namehero.com/blog/curl-headers-cookies-and-authentication/)
- [Linux Process Management: ps, htop, kill, and nice](https://www.namehero.com/blog/linux-process-management-ps-htop-kill-and-nice/)
- [Linux find with exec: + vs ;](https://www.namehero.com/blog/linux-find-with-exec-vs/)
