Questão de Linux Administration #019e3987
Which of the following settings for umask ensures that new files have the default permissions -rw-r----- ?
0017
0640
0038
0027
Explicação Oficial / Explicações da Comunidade
The umask setting determines the default permissions for newly created files and directories. The default base permissions for files are 666 (read and write for all), and for directories are 777 (read, write, execute for all). The umask value is subtracted from these base permissions to yield the actual default permissions.
How it Works
To achieve file permissions -rw-r----- (which is 640 in octal), we need to subtract the umask from the base file permissions 666. The calculation is: 666 - umask = 640. Therefore, umask = 666 - 640 = 026. However, umask values are typically given in octal and the subtraction is done digit-wise without borrowing. The correct umask is 0027, because:
- For the owner: 6 - 0 = 6 (rw-)
- For the group: 6 - 2 = 4 (r--)
- For others: 6 - 7 = -1, but since permissions cannot be negative, the result is 0 (---).
Thus, 666 - 027 = 640, which matches-rw-r-----.
Why the Correct Value is Right
The umask value 0027 correctly produces file permissions 640. The leading zero indicates octal notation. The first digit (0) is for special permissions (setuid, setgid, sticky), which are not affected here. The second digit (2) removes write permission for the group, and the third digit (7) removes all permissions for others.
Why the Incorrect Values are Wrong
0017: This umask would result in file permissions 666 - 017 = 650 (rw-r-x---), which gives execute permission to the group, not matching the required 640.0640: This is not a valid umask for files because the first digit (6) would remove read and write from the owner, resulting in permissions 666 - 640 = 026 (--w-rw---), which is incorrect.0038: This umask would give file permissions 666 - 038 = 626 (rw--w-rw-), which allows write access to others and removes read from group, not matching 640.