File Permission: What is umask & Default umask value?

  • Post last modified:April 27, 2021
  • Reading time:5 mins read

In the last article we have explain you the basics of chmod permission.

In this article, we will cover umask how to use umask command in Linux or UNIX systems.

Before that, you should know the basics of the file permissions system. If you don’t know about that, you can check our post.

Permission Command in Linux: chmod

What is umask?

UMASK stands for “User file creation mask” command, used in the Linux or UNIX system. You already know the Linux system every file has certain permission like read, write, execute to the owner, group of user, and others.

For example, when you create any file or folder in a directory using commands like mkdir, touch or any other commands.

Read this:- 30 Basic commands which every Linux user should know

By default, there is certain permission that is a default by the Linux system when a new file or directory is created.

You can set and view the default permission; It has Symbolic values and octal values.

Default umask mode

So now I’ll show you some default umask value in the home directory To check pass umask in a terminal.

$Normal user

umask as a user

The above terminal image show when we enter umask as a normal user, you will get in Octal form “0002”.

$umask

Default umask value of general user or non sudo is “0002”.

#Root User

umask as a root user
umask as a root user

The above terminal image show when we enter umask as a sudo or root user, you will get umask default value in Octal form “0022”.

#umask

Default umask value of sudo user or root user is “0022”.

Method to Calculate

To get the umask number, you have to do subtract from the base octal number to get the final umask number.

So, now I’ll show you few example’s of both directory and file.

Default umask Directory

In the Directory case base default value is 0777, and When you type the command “mkdir”, this will create a new directory.

$mkdir showcase

Linux system will automatically give you permission 775 by subtracting from base permission.

Calculation will be 777 – 022 = 755

To check the Octal value of created directory pass the below command:

$ stat -c '%A %a %n' showcase
Default umask Directory
Default umask Directory

The above terminal screen shows the octal value of the showcase directory.

Default umask for file

When you type command “touch” or any other command, this will create a new file in a directory.

Linux system will automatically give you the Octal value of 644 by subtracting from the base Octal value.

Calculation will be 666 – 022 = 644

$ stat -c '%A %a %n' *
Default umask file
Default umask file

This command shows the octal value of the current directory file.

Permission Set Using Octal

Now, we will see how we can use umask with octal in both file and folder.

$umask 075

This will set the current directory as permission of the file owner can read and write, but the group cannot access the file, but others can only update the file, but they will able to read the file.

$mkdir testfolder

For instance we will create a empty folder with a name “testfolder”.

After this when you add any file in this directory will just have “0602 permission” or octal value.

$touch filename

This will create text file with only read permission and write to user and write permission to others.

If you want to check the octal permission code

$ stat -c '%A %a %n' *
read & write only owner and others
read & write only owner and others

Through this way you can use umask with octal.

Permission Set Using Symbolic

Now you know how to use umask with octal over-here will see how we can use symbolic with umask.

Symbolic value are as follows

  • r – read
  • w – write
  • x – execute
  • u – owner
  • g – group
  • o – other

Steps to use umask

$umask u=rw,g=,o=w

The above command will change the permission value; after that, the file owner can read and write a file, the group user cannot access the file, and the last Other users can write the file.

$mkdir testfolder

This will create empty folder.

When you add any new file in this directory will just have “0604 permission”

$touch filename

This will create a text file with only read permission and write to the user and read permission to others.

If you want to check the octal permission code.

read and write permission only to user and write permission to others
read and write permission only to user and write permission to others

This was the another way to use usmask command.

Conclusion

By default, Linux systems provide base permission to both file and folder or directory.

We can change file permission through chmod also. umask default value for normal user is “0002,” and for root user is “0022”. You can even change the umask default value.

That’s all for today. I hope so you able to understand. What is umask and how to manipulate it.

Like what you read? Please share it with others.
guest
0 Comments
Inline Feedbacks
View all comments