LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   umask issues (https://www.linuxquestions.org/questions/linux-newbie-8/umask-issues-612030/)

sophisticate 01-08-2008 12:12 PM

umask issues
 
I knew that there is a diffrence between umask of folders and umask of files
and i found the umask value of folder in /etc/bashrc and i can control it but i can't find the umask of files

Dinithion 01-08-2008 12:52 PM

If your umask is i.e. 0022, then the premissions is

For files:
666 - 022 = 644 = rw-r--r--

Folders/executables:
777 - 022 = 755 = rwxr-xr-x

So as you can see, premissions for files uses 666, and folders 777, so they both use the same umask of 0022 :)

sophisticate 01-08-2008 01:25 PM

what if umask value is 037


for dir
777 - 037 = 740 rwx r-- ---
666 - 037 = 630 the value of 3 refer to what

Dinithion 01-08-2008 03:16 PM

You should read some documents on how masks and premission works.
I can give you a short summary:

1 = x
2 = w
4 = r

So as you can se, we add this up, so that
rwx = 1+2+4 = 7
rw- = 2+4 = 6
r-x = 1+4 = 5
-wx = 1+2 = 3
r-- = 4, -w- = 2, --x = 1
--- = 0

Then we use the same order, ugo. If we want to make rwxrw-r--, then we use this tabel (Or our heads as this is easy math ;)) and get 764. So insted of using:
chmod u=rwx,g=rw,o=r <file>
we use:
chmod 764 <file>
This is a training matter, and is pretty easy after a while

In your case, 3 = 1 + 2 = -wx, wich is rather useless. Good luck :)

sophisticate 01-09-2008 08:14 AM

Thanks alot for your help and i got a summry for this from RHCE book
but I;m sorry i don't understand the permission of file
let's say it is rwxrwxrwx = 4+2+1 = 777 and you said for file is only 666

Dinithion 01-09-2008 08:46 AM

That is because files and folders have different needs.

To access a folder, you need it to be executable, but it's a bad idea to have every file +x as default. Therefor it makes perfect sense to use 777 for folders and 666 for files. Try it out with different umasks. And again, I recommend you to read some documents on permissions.

Edit:
777 and 666 is just the starting point from where the rights are calculated. I can give a little example:
To have every permission on something, we use umask 000
For a folder that would be: 777, or rwx for ugo.
For a file it would be 666, or rw for ugo.

Note that umask are used when we create new files, and we would not want new files to be +x as default. We can still set the execute flag manually.

sophisticate 01-09-2008 09:07 AM

I was wondering about the values
r = 4
w = 2
x = 1
------
rwx 7 this make sence for directory but for file rwx should equal to 6
so the rwx have diffrent values than 421

Dinithion 01-09-2008 09:32 AM

No, you are confusing permissions with umask. Umask are only used when you create new files. And umask are the inverted value of the permissions.
When you decide what umask to use, you first look at what you want. If you want rw-r----- as default FILE mask, you calculate the octal value for that permission. In this case it is:
4+2+0 4+0+0 0+0+0 = 642. Since your start with a file, you subtract this from 666
666 - 640 = 026, this is your umask.
With this umask newly created files will get permission as described earlier and folders will get:
777 - 026 = 751, rwxr-x--x

On the other hand, if you want to use a folder as starting point, you figure out what rights you want the folders to have, if you want i.e. rwxr-x---, the octal value is:
4+2+1 4+0+1 0+0+0 = 750, subtract this from 777 (Since we now use folder as a starting point)
777 - 750 = 027, this is the NEW umask.
With this umask our new folders will get the desired permission (rwxr-x---). New FILES will now get this permission:
666 - 027 = 640 (They can't be -1), and would be printed as rw-r-----.
Now we got the same file permission as the first example, and that is just a coincidence, since we cant have a negative value. Try it out with different permissions/umask and create files/folders to understand it correctly.

So as we can see, there is no perfect solution. We can't have rwxrwxrwx for folders and rw-r--r-- for files, there have to be a compromise between one or the other.
I will say it again. Umask are ONLY used when you create a new file. You can modify permission as you pleases after the file/folder is created using chmod.

sophisticate 01-09-2008 09:58 AM

I'm very thankful for your explaination it's perfectly clear now and i red about umask and permission and i know most of that but the misunderstanding was in how to compromise between file and direcotry and as you explained the perfect solution up till now is chmod

kernel88 01-10-2008 12:39 PM

Quote:

Originally Posted by Dinithion (Post 3016716)
No, you are confusing permissions with umask. Umask are only used when you create new files. And umask are the inverted value of the permissions.
When you decide what umask to use, you first look at what you want. If you want rw-r----- as default FILE mask, you calculate the octal value for that permission. In this case it is:
4+2+0 4+0+0 0+0+0 = 642. Since your start with a file, you subtract this from 666
666 - 640 = 026, this is your umask.
With this umask newly created files will get permission as described earlier and folders will get:
777 - 026 = 751, rwxr-x--x

On the other hand, if you want to use a folder as starting point, you figure out what rights you want the folders to have, if you want i.e. rwxr-x---, the octal value is:
4+2+1 4+0+1 0+0+0 = 750, subtract this from 777 (Since we now use folder as a starting point)
777 - 750 = 027, this is the NEW umask.
With this umask our new folders will get the desired permission (rwxr-x---). New FILES will now get this permission:
666 - 027 = 640 (They can't be -1), and would be printed as rw-r-----.
Now we got the same file permission as the first example, and that is just a coincidence, since we cant have a negative value. Try it out with different permissions/umask and create files/folders to understand it correctly.

So as we can see, there is no perfect solution. We can't have rwxrwxrwx for folders and rw-r--r-- for files, there have to be a compromise between one or the other.
I will say it again. Umask are ONLY used when you create a new file. You can modify permission as you pleases after the file/folder is created using chmod.

Hi ! Your examples are simple and clear
But I have a question.
If umask = 333 then I calculate that NEW FILES get permission 666-333 = 333 i.e. wxwxwx. But when I check on my machine I see that NEW FILES get permission -r--r--r--. Where is my mistake ?

bahbahthelamb 01-10-2008 01:39 PM

If you know binary, permisions are easy
rwx
000 = 0
100 = 4 (Read Only)
110 = 6 (Read/Write)
111 = 7 (Executable)

The other mixes aren't used much.

-Josh

Dinithion 01-10-2008 03:31 PM

Thats a really good question. As that permission is rather useless, I have never used that one before. I think however that there is some kind of exception, as the umask is "useless". It's no good idea to have only wx to a file.

sloganyart 06-30-2008 07:44 AM

Quote:

Originally Posted by kernel88 (Post 3018011)
Hi ! Your examples are simple and clear
But I have a question.
If umask = 333 then I calculate that NEW FILES get permission 666-333 = 333 i.e. wxwxwx. But when I check on my machine I see that NEW FILES get permission -r--r--r--. Where is my mistake ?

I think you're not wrong.

The way Dinithion is calculating the permission is not correct. You should not use the decimal to subtract. For a umask of 333, you are basically having
021 user
021 group
021 other

, transform it to 'BIT' concept, it will be:

off on on -user
off on on -group
off on on -other

, and then since this is a umask, revert it to become your file permission:

on off off -user
on off off -group
on off off -other

, and transform it back to 'decimal' concept, it will be:

400 user
400 group
400 other

, which make sense you are having -r--r--r-- for the files you created.

It's funny that when Dinithion is keep on asking people to read some doc on how this works and as if he knows a lot, but in fact he is teaching people a wrong way of the knowledge. And if one is already asking question here, we shouldn't ask people to read the manual again. If one already know, he wouldn't be desperately finding solution here. So please stop asking people to 'read more docs', to me that is arrogant. Just my humble opinion. Thanks.


All times are GMT -5. The time now is 09:25 PM.