homepage Welcome to WebmasterWorld Guest from 54.211.95.201
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Changing umask
Clarifying the purpose before messing anything up
GoNC




msg:4667086
 3:09 am on Apr 30, 2014 (gmt 0)

As I mentioned in another thread, I need to share a directory with multiple accounts.

In order to do this, I understand that I need to set umask, but I'm very confused about what I'm doing, or what this does.

When I SSH to my server as root and run:

# umask

it returns 0022, which I understand is synonymous with 022.

If I need to share /home/example/www/images/ with user "new", I know that I need to run:

# umask 002

Is this a server-wide change, though, or do I run it while under /home/example/www/images/?

If it's a server-wide change, am I going to be changing the permissions of other scripts in other accounts?

I've read 20+ articles on umask, but none of them have been clear about what it is, exactly, that I'm changing. This server is my bread-and-butter, though, so I don't want to risk messing something up over a goof-off project.

 

lammert




msg:4667087
 3:23 am on Apr 30, 2014 (gmt 0)

umask is a command which for the current shell defines the default access bits used for creating new files and directories. It should be executed before new files are created, i.e. for example in the login script.

The directory where you execute the command doesn't matter because the scope of the command is the current shell and all its subshells. After issuing the command it will be effective for all new files created by those shells in all directories.

phranque




msg:4667090
 3:43 am on Apr 30, 2014 (gmt 0)

permissions are inherited, so when you set the umask for a process, it can only affect the child processes, not any parents, etc.

you are setting the umask for the process' owner essentially.

file/directory ownership comes into play with permissions but that's a separate issue from process ownership.


added: overlapping post with lammert - essentially the same message.

GoNC




msg:4667120
 7:24 am on Apr 30, 2014 (gmt 0)

The terms "shell" and "process owner" are what's confusing me. Are these synonyms for the username under which I'm logged in?

Meaning, if I'm logged in as root, it only impacts files that are created by root? Or, would accounts be children (child processes?) of root, meaning that it applies to all new files created by any user?

GoNC




msg:4667137
 8:04 am on Apr 30, 2014 (gmt 0)

(Update)

Or does it need to be ran within the script at each upload, as if I were using chmod?

For example, in Perl, would it be:

open PIC, ">/home/example/www/images/$pic";
binmode (PIC);
while ($bytes = read($old_pic,$data,16384)) { print PIC $data; }
close PIC;

umask 002;

phranque




msg:4667143
 8:28 am on Apr 30, 2014 (gmt 0)

the process running the perl program inherits its environment from the process that spawned it.
if you started the perl program from a shell as "root", then the owner of that process is "root", and it inherits everything from root's shell process.
if you need to change the umask for that perl process, it only needs to be done once within that process.

GoNC




msg:4667149
 8:49 am on Apr 30, 2014 (gmt 0)

So if I run umask 002 while SSH'ed as root, any new file created by any account will have a umask of 002?

(I'm assuming that the accounts would be a child of root)

phranque




msg:4667282
 5:14 pm on Apr 30, 2014 (gmt 0)

files don't have a umask.
processes do.
files (and directories) have permission values ("modes").
when a process requests that a file is created, a default or specified "mode" is provided to the create method.
the umask for the process that created the file will be used to disable some of the specified permissions.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved