In this tutorial you will learn about umask: check the current user value, set temporary and default value, octal and symbolic representation, computing octal value.
Code used during this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# Used as file mode creation mask # Display current value (as octal) # 0002 (for user that is created when you installed the OS) umask # Display current value symbolically # u=rwx,g=rwx,o=rx umask -S # UMASK 0022 sudo vi /etc/login.defs # Create user and change user ID sudo useradd -m -s /bin/bash -g www-data -c "Liviu Balan" liviu.balan sudo su liviu.balan # 0022 umask # Create file and dir and look at the mode bits touch ~/file.txt mkdir ~/dir # drwxr-xr-x 2 liviu.balan www-data 4096 Oct 10 10:11 dir # -rw-r--r-- 1 liviu.balan www-data 0 Oct 10 10:11 file.txt ls -l ~/ # Set temporary umask umask 0077 # u=rwx,g=,o= umask -S # 0 any permission may be set # 1 setting of execute permission is prohibited # 2 setting of write permission is prohibited # 3 setting of write and execute permission is prohibited # 4 setting of read permission is prohibited # 5 setting of read and execute permission is prohibited # 6 setting of read and write permission is prohibited # 7 all permissions are prohibited from being set # Many operating systems do not allow a file to be created with execute permissions # In these environments, newly created files will always have execute permission disabled for all users # Programmatically, the mask is applied by the OS by first negating (complementing) the mask # and then performing a logical AND with the requested file mode # UMASK 0002 # UMASK 002 (0-filled on the begining) sudo vi /etc/login.defs # Recreate user sudo userdel -rf liviu.balan sudo useradd -m -s /bin/bash -g www-data -c "Liviu Balan" liviu.balan sudo su liviu.balan # Create file and dir and look at the mode bits touch ~/file.txt mkdir ~/dir # drwxrwxr-x 2 liviu.balan www-data 4096 Oct 10 10:15 dir # -rw-rw-r-- 1 liviu.balan www-data 0 Oct 10 10:15 file.txt ls -l ~/ Useful links: http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html https://en.wikipedia.org/wiki/Umask |
Useful links:
http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
https://en.wikipedia.org/wiki/Umask