How can I set up a different umask for directories then files?
I need dirs with umask 003 and files with umask 117
Best Answer
umask is global in bash. One thing you could do is to create a mkdir wrapper(a script, you give the name to it) that would change the mask after executing it.
Remember: For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are 0666, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.
Example:
[admin@host test]$ pwd
/home/admin/test
[admin@host test]$ umask
0002
[admin@host test]$ mkdir test
[admin@host test]$ touch test_file
[admin@host test]$ ls -l
total 4
drwxrwxr-x 2 admin admin 4096 Jan 13 14:53 test
-rw-rw-r-- 1 admin admin 0 Jan 13 14:53 test_file
umaskUnix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).
Answering the question in your subject: OpenSuSE uses the traditional Unix umask setting, instead of the Debian-inspired one adopted by some other Linux distributions.
Editing /etc/login.defs should be sufficient to change it; this will not affect users currently logged in, nor is there any way for you to force such a change to programs that are currently running. It will also not affect users who have overridden it in their ~/.profile (or .bash_profile, .login, etc. as per their shell).
useradd is not involved with this; it is a per-process setting and the default is set during login (hence login.defs and not /etc/default/useradd).
Best Answer
umask
is global inbash
. One thing you could do is to create amkdir
wrapper(a script, you give the name to it) that would change the mask after executing it.This was answered here:
Remember: For directories, the base permissions are (
rwxrwxrwx
)0777
and for files they are0666
, meaning, you will not achieve execute permissions on file creation inside your shell even if the umask allows. This is clearly done to increase security on new files creation.Example:
umask
Unix Specification tells nothing about this file permission math specifics. It's up to the shell developers to decide(and OS makers).