When I create a file, the permission is 644 (user rw, group r, other r). How can I make the default file generated to have permission as 664?
5 Answers
There is a process flag in Unix/Linux called umask
, interpreted as an octal number it says which permissions to take off a newly created file. The flag is inherited by child processes. Setting it for the shell makes all processes started later to use this value.
Permissions as bits are 1 for x
, 2 for w
and 4 for r
, which can be combined into an octal digit. For example, r-x
is 4 + 1 = 5. There are 3 sets of permissions (user, group, others). So the 664 is rw-rw-r--
.
When creating a "normal" file, base permissions are 666 (nicely daemonic, isn't it?), when creating an executable it is 777. From this the umask
is taken off, 002 would give 664 for a regular file.
The shells have builtin commands called umask
to set the umask. You can run them interactively, but most often they are executed in some startup file for the shell to make it permanent. In the case of bash(1), this should be done in ~/.bashrc
. In Fedora it is set system-wide in /etc/bashrc
.
Before changing the default setting, carefully consider implications, as relaxing permissions could allow undesirable access to your files. Allowing anybody in your group writing your files is risky!
If you want to change default umask to all user, add this line:
umask 0002
to /etc/profile
.
Although any user can override this value by setting their own in ~/.bashrc
.
To calculate file permission generated by umask value, consider this formula:
generated_permission = (NOT umask) AND default_permission
where NOT
and AND
is logical bitwise operator ~
and &
.

- 153,898
-
System-wide:
/etc/profile
. There is user-specific~/.profile
. Is there any reason you mention~/.bashrc
instead? What is the difference between the two user-specific files. – Trudy Dec 15 '21 at 18:22
In former times (in the 1970s) people did write simple code that causes things to be hard to understand. This is what the other answers are related to.
If you are using a shell that is less than 30 years old, you may do this in a way that is easier to understand:
umask g+w
This is nicer since in this mode, the mask is inverted.
Background: the kernel interface still manages a mask that is applied to the third parameter of open()
.
Since 1988 (with ksh88) a new shell interface for the chmod
command in the shell has been established.
umask -S
prints the file creation mode mask in the modern symbolic chmod
syntax and
umask u=rw,g=rw,o=r
allows to set the file creation mask using the chmod
syntax.

- 19,173
If you want to set the permission temperorily Use below command
Example: umask 022
In above case user have rw Permission
Group have read permission
Others have read permission
How it is calculated
for file we will calculate like this
Suppose if you want only read permission calculated like this
since read permission value is 4 so we need to get value of 4 post subtracting
Totalvalue(6) - writevalue(2) =4(Read)

- 5,211
umask
takes pernissions away from the base 0666 (regular file) or 0777 (executable, directory). It can't add permissions. – vonbrand Feb 11 '21 at 12:39