Short answer: umask has four digits and it does not change arbitrarily, but / etc / profile and fiends set it to 022 by default.
Update
I somehow got carried away with this and forgot to answer your question correctly:
Make sure that the partition (if any) installed in the folder you are entering does not have the umask set. (just type mount )
Long answer:
man chmod Β§ 6: Numeric mode - from one to four octal digits (0-7), obtained by adding bits with values ββ4, 2 and 1. The assumed digits are considered leading zeros. The first digit selects the set user identifier (4) and sets the group identifier (2) and the restricted deletion or sticky (1) attributes. The second digit selects the permissions for the user who owns the file: read (4), write (2) and execute (1); the third chooses permissions for other users in the file group, with the same values; and the fourth for other users not in the file group, with the same values.
GNU coreutils 8.14 October 2011
I remember reading this manual page a few years ago, and never quite realizing what all of this means before I set up the table. Since I lost my lookup table, I will restore it here. Since I do not like the symbolic one but because it is more cumbersome to type (for example, chmod u + x), I will not be any mention of this.
Interpretation of chmod and umask
Possible settings: 4: read 2: write 1: execute
Possible values ββof each digit with examples
domain setuid user group world
digit 1 2 3 4
values ββ0-7 0-7 0-7 0-7
The "possible installation" values ββin curly braces {} can be added together to create a valid permission bit (number).
Common examples
0755: the user can enter the folder and write (delete) files in this folder. If this mask is set in the file, the user can execute the file (i.e. /filenme.bin). The last two digits mean that the group, the file belongs, and the world (anyone else on the system) can execute the file as well. Applied to directories, this means that the group and the world can enter this directory.
0644: The user can read and write the file, but not execute it. The group and the world can only read the file. For a folder, this mask prevents anyone from this directory.
0600: Only the owner can read and write a file with this mask
0700: Only the owner of a folder can enter, read, and write the contents of a folder with this mask.
0000: useful for βhidingβ files or for signaling (for yourself) that a file or folder should not be used.
Masks of meaningless
0200: If the user can write the file, he can also change the umask of the file.
Dangerous masks
0666: anyone can read, write and delete a file using this mask
0777: The same goes for the folder. If the binary is installed 777, then anyone can whatever they want in this file, and run it, even if it is on the system, a wide directory of binary files, such as / usr / bin.
4755: binaries owned by the superuser (root) will work with superuser permissions. The implications of this should be clear. Perhaps the intuitive setup of the interpreted script with 4755 will not have any effect since the script (e.g. bash script) is still running / bin / bash. The text file in which the script is stored is not executable.
In all of the above examples, the leading zero may be omitted for convenience.
Convert umask to chmod
To set the correct umask, all you have to do is subtract unwanted permissions from the "maximum mask", which is 0777 for folders and 666 for files.
To force the shell to create files with a default resolution of 644, set umask to 0022. For folders, the typical (desired) umask can be 755 and obtained by setting umask to 0022.
0666 0777
-0022 -0022
____ ____
0644 0755
Relative links: https://unix.stackexchange.com/questions/364/allow-setuid-on-shell-scripts