LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-08-2008, 12:12 PM   #1
sophisticate
Member
 
Registered: Oct 2007
Distribution: CentOS 5
Posts: 39

Rep: Reputation: 15
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
 
Old 01-08-2008, 12:52 PM   #2
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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

Last edited by Dinithion; 01-08-2008 at 12:53 PM.
 
Old 01-08-2008, 01:25 PM   #3
sophisticate
Member
 
Registered: Oct 2007
Distribution: CentOS 5
Posts: 39

Original Poster
Rep: Reputation: 15
what if umask value is 037


for dir
777 - 037 = 740 rwx r-- ---
666 - 037 = 630 the value of 3 refer to what
 
Old 01-08-2008, 03:16 PM   #4
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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
 
Old 01-09-2008, 08:14 AM   #5
sophisticate
Member
 
Registered: Oct 2007
Distribution: CentOS 5
Posts: 39

Original Poster
Rep: Reputation: 15
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

Last edited by sophisticate; 01-09-2008 at 08:19 AM.
 
Old 01-09-2008, 08:46 AM   #6
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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.

Last edited by Dinithion; 01-09-2008 at 08:50 AM.
 
Old 01-09-2008, 09:07 AM   #7
sophisticate
Member
 
Registered: Oct 2007
Distribution: CentOS 5
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 01-09-2008, 09:32 AM   #8
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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.
 
Old 01-09-2008, 09:58 AM   #9
sophisticate
Member
 
Registered: Oct 2007
Distribution: CentOS 5
Posts: 39

Original Poster
Rep: Reputation: 15
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
 
Old 01-10-2008, 12:39 PM   #10
kernel88
LQ Newbie
 
Registered: Jun 2007
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by Dinithion View Post
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 ?
 
Old 01-10-2008, 01:39 PM   #11
bahbahthelamb
Member
 
Registered: Jul 2006
Location: Fort Worth, Texas
Distribution: openSUSE 11, RHEL4 & 5, CentOS 5
Posts: 56

Rep: Reputation: 16
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
 
Old 01-10-2008, 03:31 PM   #12
Dinithion
Member
 
Registered: Oct 2007
Location: Norway
Distribution: Slackware 13.37
Posts: 436

Rep: Reputation: 56
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.
 
Old 06-30-2008, 07:44 AM   #13
sloganyart
LQ Newbie
 
Registered: Jan 2007
Location: Johor, Malaysia
Distribution: Slackware 9.2,12.2,13.0, Debian woody,sarge,etch,Centos5.3
Posts: 22

Rep: Reputation: 15
Quote:
Originally Posted by kernel88 View Post
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.
 
  


Reply

Tags
permission, umask


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When and why to use Umask ? tofee Linux - Newbie 4 11-26-2009 09:21 AM
umask trophy Linux - General 1 04-03-2004 01:17 AM
umask=0,0,0 demmylls Linux - General 2 09-15-2003 12:13 PM
umask knueven7 Linux - Newbie 8 04-18-2003 07:30 AM
Umask def1014 Linux - Security 3 06-21-2002 04:05 AM


All times are GMT -5. The time now is 06:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration