I don't seem to be able to use umask
to make sure my default file permission is 755. I need it because every time I check out a script file on CentOS
from my version control, it doesn't have the x permission and I have to manually chmod +x script.sh
. How to umask to get default file permission of 755? Why is the umask calculation for files based off of 666 as the maximum permission for files and not 777?

- 12,472
- 18
- 64
- 88
-
2What version control are you using? – thrig Mar 27 '17 at 15:51
-
1See http://unix.stackexchange.com/questions/102075/why-are-666-the-default-file-creation-permissions – fpmurphy Mar 27 '17 at 18:21
-
It's a POSIX standard; see also http://askubuntu.com/a/754313 and http://unix.stackexchange.com/questions/287278/why-doesnt-umask-change-execute-permissions-on-files?rq=1 – ILMostro_7 Mar 27 '17 at 22:23
-
@thrig asked the right question. The version control system is crucial to this situation. – Wildcard Oct 17 '17 at 22:13
2 Answers
The permissions a file gets can only be reduced by the umask, so no, you can't use it to add permissions. Also, unlike you claim, the permissions before reducing the masked bits are not 0666 or 0777 but whatever the program in question sets. The usual custom is to create normal files with mode 0666 and directories with 0777 and let the umask handle limiting access for other users, but a program that is creating especially private files would use 0600 as the starting permissions.
If you need an application to create files with certain permissions, you need to fix it on the application level. For Subversion, see the svn:executable
property.

- 138,973
An option is to create a funciton in your .bashrc (if you are using bash) that will do two things.
- check out the script
chmod +x script.sh
myfunction () { #do things with parameters like $1 such as checkout_command $1 chmod +x $1 } #calls `myfunction` to checkout the script and chmod on the fly. myFunction my_script.sh

- 750