Why are you using umask?

I am reading some source code, and I found this statement at the very beginning of the main procedure:

umask(077);

What could be the reason for this?

The man page (man 2 umask) states:

umask - set file creation mode mask

This cleanup allows each user to restrict the default access to their files.

But I don’t understand why anyone should do this? how's the shortcut?

+5
source share
3 answers

The setting umask(077)ensures that any files created by the program will be available only to their owner (0 in the first position = all allowed potentially available), and no one else (7 in the second / third position = all permissions prohibited for the group / other).

+10

. umask , .

dzen@DZeN ~ $ umask
022
dzen@DZeN ~ $ touch file
dzen@DZeN ~ $ ls -la file
-rw-r--r--  1 dzen  dzen  0  6 may 14:29 file
dzen@DZeN ~ $ umask 777
dzen@DZeN ~ $ umask      
0777
dzen@DZeN ~ $ touch file1
dzen@DZeN ~ $ ls -la file1
----------  1 dzen  dzen  0  6 may 14:30 file1
+4

All Articles