In the past, I have always set umask
at ~/.profile
. I set a umask
of 077
so my documents get a permission of 600 (rw-------)
. But setting this at ~/.profile
no longer works in Ubuntu 17.04.
So as new documents get created in a gnome session on Ubuntu 17.04, where can I configure so that they get created with permission 600?
To set permissions for all directories and files that are created day-forward by any user:
New files will be 600. New directories will be 700.
tl; dr: Replace
UMASK 022
by e.g.UMASK 027
in file/etc/login.defs
but doesn't work 100%.Documentation
See the man pages (20.04) for info on this. There are several places where it can be set: I used
/etc/pam.d/login
or/etc/default/login
in the past but stopped working so now I'm using/etc/login.defs
which partially works.Ubuntu 18.04, Ubuntu 20.04
In file
/etc/login.defs
there is an entryUMASK 022
that can be replaced by, in my case,UMASK 027
. Then reboot. This yields:Ubuntu 18.04:
Ubuntu 20.04:
Might work in 17.04
Note this file does not exist on my version of Ubuntu, in which case we can create it.
Evil Bug
Now if we restart and ask for the umask in the terminal we still get
0022
(in the case of Ubuntu 18.04) and not the0027
that was set. See Bug #1685754.But if we open an application, for example the Text Editor, and save a file we'll notice the new umask affected permissions. Open it from the menu, not from the terminal as it seems to pick up the (bad)
umask
from the terminal.References
pam_umask
I have recently came across this on Ubuntu 20.04 TLS and found the solution.
This will get us the location of manual pages that discuss umask - all information can be found there.
From /etc/pam.d/common-session:
From PAM_UMASK(8):
Notice the text in the brackets: influenced by USERGROUPS_ENAB in /etc/login.defs.
What is USERGROUPS_ENAB?
From /etc/login.defs:
You can now run this:
to double-check if you have USERGROUPS_ENAB set to "yes", if it's uncommented (default), and on which line of the document can you find it.
Therefore, when you change the default "UMASK 022" to "UMASK 027", if USERGROUPS_ENAB is set to "yes", you will see that your umask has been set to 007 (not 027) - as it ignores the 2nd position (group permissions).
The solution to this is simple: uncomment the line where "USERGROUPS_ENAB" is set to "yes". If you have changed umask value to "UMASK 027", you will have umask set to 027 after the reboot.
You can verify this by running this in your shell.
To summarize, the only config file that matters is /etc/login.defs.
Set your umask to desired value and make sure to uncomment USERGROUPS_ENAB line to change group permissions as well.
Hope this helps.
That's literally what your
~/.profile
says. Did you relogin once changed? It should work fine.Also:
Actually confirmed the issue on a freshly installed ubuntu 17.04. Even fully updating still causes this issue to arise and even
~/.bash_profile
is ignored, there seems to be an issue with the command interpreter not reading those files after login.You can use
~/.bashrc
for now, which still works fine and is read during login.So after digging a little into it, it seems bash is not run by default with the --login anymore which means it doesn't read the ~/.profile. Starting a new bash with the umask in ~/.profile with
bash --login
sets the umask correctly starting a bash without it though ignores the ~/.profile. Not sure what was changed but this seems like a bug to me unless it was intentionally changed.If you're using GDM, it doesn't read
~/.profile
like LightDM does. And the terminal normally opens a non-login shell. The net effect is that~/.profile
is not loaded at all when you open a terminal after logging in using GDM.Either:
~/.bashrc
, orOn Ubuntu 18.04.3 I have tried to create
/etc/default/login
withsession optional pam_umask.so umask=0027
as Daniel says but not worked for me, instead I have changed the umask in/etc/login.defs
and it worked.I have changed umask value in 002 and now all the users create files with full permission also for their own group.
I have the workaround at least on Fedora 31: