Operating System - HP-UX
1837976 Members
2434 Online
110124 Solutions
New Discussion

Re: Automstic Permissions

 
hmorrison
Advisor

Automstic Permissions

If I need all the files that will be created by a particular to have special permissions set on them, how do I do it automically as the files asre created. I know that chmod -R 774 will set the permissions after the file, have been created. Can anyone assist?
8 REPLIES 8
Jeff_Traigle
Honored Contributor

Re: Automstic Permissions

man 1 umask
--
Jeff Traigle
IT_2007
Honored Contributor

Re: Automstic Permissions

you can set umask 022 in /etc/profile so that it will set permissions globally.
Jaime Bolanos Rojas.
Honored Contributor

Re: Automstic Permissions

Hmorrison,

Also take a look at this document:

http://docs.hp.com/en/B2355-90164/ch07s08.html

Regards,

Jaime.
Work hard when the need comes out.
Patrick Wallek
Honored Contributor

Re: Automstic Permissions

Be aware that unless a file is a binary executable program or a shell/perl script that needs to be run, then the 'x' bit should NOT be set.

The default permissions for a regular file are '666' (rw-rw-rw-) and the umask is "subtracted" from it.

The is no real easy way to make a regular file have the 'x' bit set by default.
A. Clay Stephenson
Acclaimed Contributor

Re: Automstic Permissions

The default mode for a regular file is 666 under the shell and then umask kinda, sorta "subtracts" from that. Umask cannot put back what is not there in the first place. In languages such a C or Perl is is possible to set the execute (or any other) bits when a file is created but under the shell an explicit chmod is required after the file is created.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Automstic Permissions

Hi:

If you are looking to create a file in a shell script with execute permissions for the owner and/or group, you can't.

The shell uses a permissions argument to open() of octal 0666 which is then modified by the 'umask' value as noted.

In a shell program, you cannot specify the mode.

Regards!

...JRF...
Sp4admin
Trusted Contributor

Re: Automstic Permissions

Hello,

You can set the "umask" in the .profile of the user or at the Global.

man umask

sp,
Bill Hassell
Honored Contributor

Re: Automstic Permissions

You said:

> chmod -R 774

There are things very wrong with this command. The first is that chmod -R is one the most dangerous commands in Unix. It is recursive which means it changes directory and every file from the starting point you give it. If you are root and are sitting at the worst possible location (/) then the command above would destroy your system and would require a complete re-install, either with Ignite/UX or with your CD's , DVD's and patches, and applications, etc. Never use -R until you thoroughly understand the meaning.

Second, 774 is a bad setting for ordinary files. I know that some beginner's books and even classes on Unix will say chmod 774 or 777 is recommended but they are flat out wrong. The vast majority of files in Unix are *NOT* executable and should never be made executable. An interesting thread here in the ITRC showed how a data file created an endless loop when the DBA logged in and it impacted every user on the system.

So do not set the execute on any file unless it is a script (shell, Perl, awk, etc). The correct permission for all files is 6 for the owner, 6 or 4 for group and 0 or 4 for the rest of the world. 666 means that the contents of the file will eventually be trashed, either on puepose or by accident. That is the whole point behind permissions.


Bill Hassell, sysadmin