Operating System - HP-UX
1838703 Members
3497 Online
110128 Solutions
New Discussion

Basic File Permissions Question

 
walztoni
Occasional Contributor

Basic File Permissions Question

What causes a particular set of file permissions, let's say (rwxr--r--), to be set when a user creates a file?
Thanks you,
Paul Walztoni
walztoni@morainevalley.edu
5 REPLIES 5
Sanjay Kumar Suri
Honored Contributor

Re: Basic File Permissions Question

umask. generally umask is set to 022. can be changed with umask command.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Peter Leddy_1
Esteemed Contributor

Re: Basic File Permissions Question

Hi,

It is based on what the umask is set as on the system. man umask will give you more details on it.

HTH,

Peter
Chris Wilshaw
Honored Contributor

Re: Basic File Permissions Question

It is set through the umask command, although that could only allow you to create files with r/w permissions - x (execute) is always disabled

umask 022 creates files with -rw-r--r-- permissions

the permissions are defined as 6-(mask)

therefore umask 000 creates files with -rw-rw-rw- (666 permissions), and umask 666 creates files with ---------- permissions.
walztoni
Occasional Contributor

Re: Basic File Permissions Question

Thank you all very much. That helps. Paul
A. Clay Stephenson
Acclaimed Contributor

Re: Basic File Permissions Question

There are actually two things at play, the 'mode' that is used to create the file and the 'umask' which essentially "subtracts" from the mode.

Under an application, you have much more control over the mode of the file; under the shell, regular files are given a mode of 666 (rw-rw-rw-) and directories are given a mode of 777. Depending upon the umask setting those values are left intact or are "subtracted" to be left in a more restrictive mode. It is often tempting to set umask to 0000 for the sake of convenience but that leaves files accessiable for everyone and is a big security hole. At a bare minimum you should use a umask of 002 and 022 is generally a better choice.

Note: There is no way to make a regular file (e.g. a shell script) executable in one step.
A regular file is given a default mode of 666 (subject to "subtraction" by umask); a subsequent chmod (e.g. chmod 755) must be added to set the execution bit(s).

If it ain't broke, I can fix that.