In this video, you'll learn about default permissions.
So how does it work?
Well, there is UMask.
UMask is a shell setting that subtracts the UMask
from the default permissions.
The default UMask is set in ETC Bash RC,
and it should be set in the shell
because it applies to everything that is
happening in a specific shell.
If you want to use a specific override,
you can do so in the user-specific Bash RC,
which is .bashrc in the user home directory.
Now, to understand the UMask is the subtraction
from the default permissions.
And the default permissions for file are 666.
The default permissions for directory are 777.
And as a result, if you have UMask 022,
well, 666 minus 022 gives 644, and 777 minus 022
gives 755.
Or if you have UMask 027, that will give 640 on files.
You don't get minus 1 because that's not a valid permission,
and you would get 750 on directories.
Be careful.
Don't tweak the UMask without fully understanding
what is happening.
You might be tempted to say, hey,
I'm going to change my UMask to make sure
that everything that Root is creating
doesn't read and execute for others.
Well, in many cases, these are essential permissions.
So be very careful if you are going to tweak the UMask.
Let me show you how it works.
So to start it, I'm typing UMask,
and there we can see the default UMask.
It has a leading 0.
The leading 0 is for the special permissions.
Just ignore it.
Drop it.
It's 022.
You will never use anything but 0 as the first position.
And that is why a three-digit UMask will work as well.
So if I would use UMask 027 and I type UMask again,
then we can see it's set to 0027.
And when I would use touch file 3,
ls minus l on file 3 is giving the default permissions as 640.
That's what we wanted.
Now, how does this UMask work?
Well, I would say grab on the UMask on .bashrc.
And apparently, we don't have default UMask here.
And what if we grab on UMask in etc.bashrc?
There we get the default UMask setting.
Now, this is a shell script which
is saying UMask minus equal 0 and UMask 022, which
means if the UMask is not currently set,
then we are going to set the UMask to 022.
That's default UMask.
As I told you, don't change it.
There's a serious risk that things go wrong
if you change the UMask, so don't do it.