I want to set the UMASK value for non root users as 077 and for the root users it should be 022.
I have changed the UMASK value in /etc/login.defs
from 022 to 077. But this seems to change the UMASK of my root user as well. Is there a way in which I can only change the UMASK value of new non-root users that are created?
Note: I need to be able to do this in a script.
You could just put umask 022
in your root's .profile
/.bashrc
and have 077 as a default in your /etc/login.defs
.
The umask
shell builtin makes the umask
system call which sets process-inheritable the umask
property: a umask call set in one process affects all descendants of that process (unless they themselves make a umask
call), so to set a umask
for "user", you need to call umask
in a process from which all user processes descend (the login shell and/or the shell through which sudo
commands are invoked).