How is umask calculated in Linux?What is the first digit in umask value?Leading zero in umask 0022Why do some umask values not take effect?Umask not workingHow to check umask for all users under Linux?Umask for root and other system usersmount command permissions: ntfs vs. ntfs-3gHow umask worksWhat is the first digit in umask value?Leading zero in umask 0022How to permanently change umask value from 0002 to 0022?Setting umask for GNOME sessionWhy do some umask values not take effect?How do I make any newly created file in a specific directory executable, readable and writable by default by all users
How dangerous is XSS?
Is there a hemisphere-neutral way of specifying a season?
What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"
One verb to replace 'be a member of' a club
How can saying a song's name be a copyright violation?
Intersection Puzzle
Should I tell management that I intend to leave due to bad software development practices?
What's the in-universe reasoning behind sorcerers needing material components?
How do I know where to place holes on an instrument?
In 'Revenger,' what does 'cove' come from?
What mechanic is there to disable a threat instead of killing it?
How to compactly explain secondary and tertiary characters without resorting to stereotypes?
Bullying boss launched a smear campaign and made me unemployable
How do I deal with an unproductive colleague in a small company?
What killed these X2 caps?
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
How much of data wrangling is a data scientist's job?
How does a predictive coding aid in lossless compression?
CAST throwing error when run in stored procedure but not when run as raw query
How seriously should I take size and weight limits of hand luggage?
What is the most common color to indicate the input-field is disabled?
How do I handle a potential work/personal life conflict as the manager of one of my friends?
Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?
How to prevent "they're falling in love" trope
How is umask calculated in Linux?
What is the first digit in umask value?Leading zero in umask 0022Why do some umask values not take effect?Umask not workingHow to check umask for all users under Linux?Umask for root and other system usersmount command permissions: ntfs vs. ntfs-3gHow umask worksWhat is the first digit in umask value?Leading zero in umask 0022How to permanently change umask value from 0002 to 0022?Setting umask for GNOME sessionWhy do some umask values not take effect?How do I make any newly created file in a specific directory executable, readable and writable by default by all users
So I know umask
can restrict privileged users, using this format umask ugo
.
I understand that the read = 4, write = 2, and exec = 1. However, when I type umask
, it returns 4 digits which is 0022
or 0073
. I have no understanding of how does this work now because there is an extra digit. What is that extra digit and what does 0022
mean?
umask
add a comment |
So I know umask
can restrict privileged users, using this format umask ugo
.
I understand that the read = 4, write = 2, and exec = 1. However, when I type umask
, it returns 4 digits which is 0022
or 0073
. I have no understanding of how does this work now because there is an extra digit. What is that extra digit and what does 0022
mean?
umask
add a comment |
So I know umask
can restrict privileged users, using this format umask ugo
.
I understand that the read = 4, write = 2, and exec = 1. However, when I type umask
, it returns 4 digits which is 0022
or 0073
. I have no understanding of how does this work now because there is an extra digit. What is that extra digit and what does 0022
mean?
umask
So I know umask
can restrict privileged users, using this format umask ugo
.
I understand that the read = 4, write = 2, and exec = 1. However, when I type umask
, it returns 4 digits which is 0022
or 0073
. I have no understanding of how does this work now because there is an extra digit. What is that extra digit and what does 0022
mean?
umask
umask
edited Dec 31 '14 at 2:55
muru
37k589164
37k589164
asked Jul 27 '13 at 22:52
BraiamBraiam
23.8k2077142
23.8k2077142
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Assume the default mask of 0666. umask
0022 would make the new mask 0644 (0666-0022=0644) meaning that group and others have read (no write or execute) permissions.
The "extra" digit (the first number = 0), specifies that there are no special modes.
If mode begins with a digit it will be interpreted as octal otherwise its meant to be symbolic.
0 is a digit, as is 1 (for the sticky bit) or 6 (for SGID). A command such as chmod
can be called by other methods, such as chmod ug+rw mydir
where you would add the read and write permissions to user and group. Note that the mode in this case (ug+rw) does not begin with a digit, thus would not be interpretted as octal but rather symbolic.
See en.wikipedia.org/wiki/Chmod#Symbolic_examples for symbolics as well as www.lifeaftercoffee.com/2007/03/20/special-permission-modes-in-linux-and-unix/ for a bit on special modes.
I don't know that you would unmask the first bit with umask
, but technically you could. It would explain why you almost always see it as a zero.
Credit to pinkfloydx33
The first digit of the mask deals with special permissions that don't fit quite so cleanly into the owner/group/other model. When four digits are provided for a file permission, the first refers to those special values:
4000 = SUID
2000 = SGID
1000 = sticky bit
The SUID bit, short for set-user-ID, causes an executable program to run with the effective user id (uid) of the owner -- in other words, no matter who executes it, the program executes with the owner's rights. This is commonly seen in programs that do things that require root privileges, but are meant to be run by normal users: passwd
is one such example.
The SGID bit, short for set-group-ID, is very similar, but runs with the effective group id (gid) of the owner.
The sticky bit is a little more complicated, if you want more information on that, you can read the manpage for sticky
.
These bits can also be used with directories, but their meanings change.
I don't believe you can actually set the umask
to allow you to enable any of these extra bits by default, but you probably would never want to do that anyways.
Credit to user470379
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According toman 2 umask
(the corresponding system call) "only the file permission bits ofmask
are used". Inbash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.
– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have writtenchmod 6777 dropbox
. And, by the way, alsochmod ug+s
.)
– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not0666-0022
, it's0666 & ~0022
.
– cuonglm
Dec 31 '14 at 1:44
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
|
show 6 more comments
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f84676%2fhow-is-umask-calculated-in-linux%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Assume the default mask of 0666. umask
0022 would make the new mask 0644 (0666-0022=0644) meaning that group and others have read (no write or execute) permissions.
The "extra" digit (the first number = 0), specifies that there are no special modes.
If mode begins with a digit it will be interpreted as octal otherwise its meant to be symbolic.
0 is a digit, as is 1 (for the sticky bit) or 6 (for SGID). A command such as chmod
can be called by other methods, such as chmod ug+rw mydir
where you would add the read and write permissions to user and group. Note that the mode in this case (ug+rw) does not begin with a digit, thus would not be interpretted as octal but rather symbolic.
See en.wikipedia.org/wiki/Chmod#Symbolic_examples for symbolics as well as www.lifeaftercoffee.com/2007/03/20/special-permission-modes-in-linux-and-unix/ for a bit on special modes.
I don't know that you would unmask the first bit with umask
, but technically you could. It would explain why you almost always see it as a zero.
Credit to pinkfloydx33
The first digit of the mask deals with special permissions that don't fit quite so cleanly into the owner/group/other model. When four digits are provided for a file permission, the first refers to those special values:
4000 = SUID
2000 = SGID
1000 = sticky bit
The SUID bit, short for set-user-ID, causes an executable program to run with the effective user id (uid) of the owner -- in other words, no matter who executes it, the program executes with the owner's rights. This is commonly seen in programs that do things that require root privileges, but are meant to be run by normal users: passwd
is one such example.
The SGID bit, short for set-group-ID, is very similar, but runs with the effective group id (gid) of the owner.
The sticky bit is a little more complicated, if you want more information on that, you can read the manpage for sticky
.
These bits can also be used with directories, but their meanings change.
I don't believe you can actually set the umask
to allow you to enable any of these extra bits by default, but you probably would never want to do that anyways.
Credit to user470379
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According toman 2 umask
(the corresponding system call) "only the file permission bits ofmask
are used". Inbash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.
– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have writtenchmod 6777 dropbox
. And, by the way, alsochmod ug+s
.)
– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not0666-0022
, it's0666 & ~0022
.
– cuonglm
Dec 31 '14 at 1:44
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
|
show 6 more comments
Assume the default mask of 0666. umask
0022 would make the new mask 0644 (0666-0022=0644) meaning that group and others have read (no write or execute) permissions.
The "extra" digit (the first number = 0), specifies that there are no special modes.
If mode begins with a digit it will be interpreted as octal otherwise its meant to be symbolic.
0 is a digit, as is 1 (for the sticky bit) or 6 (for SGID). A command such as chmod
can be called by other methods, such as chmod ug+rw mydir
where you would add the read and write permissions to user and group. Note that the mode in this case (ug+rw) does not begin with a digit, thus would not be interpretted as octal but rather symbolic.
See en.wikipedia.org/wiki/Chmod#Symbolic_examples for symbolics as well as www.lifeaftercoffee.com/2007/03/20/special-permission-modes-in-linux-and-unix/ for a bit on special modes.
I don't know that you would unmask the first bit with umask
, but technically you could. It would explain why you almost always see it as a zero.
Credit to pinkfloydx33
The first digit of the mask deals with special permissions that don't fit quite so cleanly into the owner/group/other model. When four digits are provided for a file permission, the first refers to those special values:
4000 = SUID
2000 = SGID
1000 = sticky bit
The SUID bit, short for set-user-ID, causes an executable program to run with the effective user id (uid) of the owner -- in other words, no matter who executes it, the program executes with the owner's rights. This is commonly seen in programs that do things that require root privileges, but are meant to be run by normal users: passwd
is one such example.
The SGID bit, short for set-group-ID, is very similar, but runs with the effective group id (gid) of the owner.
The sticky bit is a little more complicated, if you want more information on that, you can read the manpage for sticky
.
These bits can also be used with directories, but their meanings change.
I don't believe you can actually set the umask
to allow you to enable any of these extra bits by default, but you probably would never want to do that anyways.
Credit to user470379
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According toman 2 umask
(the corresponding system call) "only the file permission bits ofmask
are used". Inbash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.
– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have writtenchmod 6777 dropbox
. And, by the way, alsochmod ug+s
.)
– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not0666-0022
, it's0666 & ~0022
.
– cuonglm
Dec 31 '14 at 1:44
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
|
show 6 more comments
Assume the default mask of 0666. umask
0022 would make the new mask 0644 (0666-0022=0644) meaning that group and others have read (no write or execute) permissions.
The "extra" digit (the first number = 0), specifies that there are no special modes.
If mode begins with a digit it will be interpreted as octal otherwise its meant to be symbolic.
0 is a digit, as is 1 (for the sticky bit) or 6 (for SGID). A command such as chmod
can be called by other methods, such as chmod ug+rw mydir
where you would add the read and write permissions to user and group. Note that the mode in this case (ug+rw) does not begin with a digit, thus would not be interpretted as octal but rather symbolic.
See en.wikipedia.org/wiki/Chmod#Symbolic_examples for symbolics as well as www.lifeaftercoffee.com/2007/03/20/special-permission-modes-in-linux-and-unix/ for a bit on special modes.
I don't know that you would unmask the first bit with umask
, but technically you could. It would explain why you almost always see it as a zero.
Credit to pinkfloydx33
The first digit of the mask deals with special permissions that don't fit quite so cleanly into the owner/group/other model. When four digits are provided for a file permission, the first refers to those special values:
4000 = SUID
2000 = SGID
1000 = sticky bit
The SUID bit, short for set-user-ID, causes an executable program to run with the effective user id (uid) of the owner -- in other words, no matter who executes it, the program executes with the owner's rights. This is commonly seen in programs that do things that require root privileges, but are meant to be run by normal users: passwd
is one such example.
The SGID bit, short for set-group-ID, is very similar, but runs with the effective group id (gid) of the owner.
The sticky bit is a little more complicated, if you want more information on that, you can read the manpage for sticky
.
These bits can also be used with directories, but their meanings change.
I don't believe you can actually set the umask
to allow you to enable any of these extra bits by default, but you probably would never want to do that anyways.
Credit to user470379
Assume the default mask of 0666. umask
0022 would make the new mask 0644 (0666-0022=0644) meaning that group and others have read (no write or execute) permissions.
The "extra" digit (the first number = 0), specifies that there are no special modes.
If mode begins with a digit it will be interpreted as octal otherwise its meant to be symbolic.
0 is a digit, as is 1 (for the sticky bit) or 6 (for SGID). A command such as chmod
can be called by other methods, such as chmod ug+rw mydir
where you would add the read and write permissions to user and group. Note that the mode in this case (ug+rw) does not begin with a digit, thus would not be interpretted as octal but rather symbolic.
See en.wikipedia.org/wiki/Chmod#Symbolic_examples for symbolics as well as www.lifeaftercoffee.com/2007/03/20/special-permission-modes-in-linux-and-unix/ for a bit on special modes.
I don't know that you would unmask the first bit with umask
, but technically you could. It would explain why you almost always see it as a zero.
Credit to pinkfloydx33
The first digit of the mask deals with special permissions that don't fit quite so cleanly into the owner/group/other model. When four digits are provided for a file permission, the first refers to those special values:
4000 = SUID
2000 = SGID
1000 = sticky bit
The SUID bit, short for set-user-ID, causes an executable program to run with the effective user id (uid) of the owner -- in other words, no matter who executes it, the program executes with the owner's rights. This is commonly seen in programs that do things that require root privileges, but are meant to be run by normal users: passwd
is one such example.
The SGID bit, short for set-group-ID, is very similar, but runs with the effective group id (gid) of the owner.
The sticky bit is a little more complicated, if you want more information on that, you can read the manpage for sticky
.
These bits can also be used with directories, but their meanings change.
I don't believe you can actually set the umask
to allow you to enable any of these extra bits by default, but you probably would never want to do that anyways.
Credit to user470379
edited May 23 '17 at 12:40
Community♦
1
1
answered Jul 27 '13 at 22:52
BraiamBraiam
23.8k2077142
23.8k2077142
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According toman 2 umask
(the corresponding system call) "only the file permission bits ofmask
are used". Inbash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.
– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have writtenchmod 6777 dropbox
. And, by the way, alsochmod ug+s
.)
– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not0666-0022
, it's0666 & ~0022
.
– cuonglm
Dec 31 '14 at 1:44
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
|
show 6 more comments
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According toman 2 umask
(the corresponding system call) "only the file permission bits ofmask
are used". Inbash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.
– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have writtenchmod 6777 dropbox
. And, by the way, alsochmod ug+s
.)
– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not0666-0022
, it's0666 & ~0022
.
– cuonglm
Dec 31 '14 at 1:44
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
1
1
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According to
man 2 umask
(the corresponding system call) "only the file permission bits of mask
are used". In bash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.– rici
Jul 28 '13 at 1:29
Actually, you can't supply a non-zero value other than in the last 3 digits. According to Posix: "The interpretation of mode values that specify file mode bits other than the file permission bits is unspecified." According to
man 2 umask
(the corresponding system call) "only the file permission bits of mask
are used". In bash
, umask 1000 generates an error: "octal number out of range". So why the extra 0? I think it's just to show that the number is in octal.– rici
Jul 28 '13 at 1:29
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have written
chmod 6777 dropbox
. And, by the way, also chmod ug+s
.)– rici
Jul 28 '13 at 2:17
that pastebin has no reference whatsoever to umask, so I don't see how it's relevant. chmod does allow the first three bits to be set, but umask doesn't allow them to be masked. (i.e. you could have written
chmod 6777 dropbox
. And, by the way, also chmod ug+s
.)– rici
Jul 28 '13 at 2:17
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
Yeah, you are right, don't know what was I thinking.
– Braiam
Jul 28 '13 at 13:11
@Braiam: Your formula to calculate new mask is wrong, it's not
0666-0022
, it's 0666 & ~0022
.– cuonglm
Dec 31 '14 at 1:44
@Braiam: Your formula to calculate new mask is wrong, it's not
0666-0022
, it's 0666 & ~0022
.– cuonglm
Dec 31 '14 at 1:44
1
1
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
I think the objection is not the way the numbers are written, but the use of the subtraction operator (-) instead of bitwise and (&).
– BowlOfRed
Dec 31 '14 at 3:11
|
show 6 more comments
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f84676%2fhow-is-umask-calculated-in-linux%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown