Operating System - HP-UX
1837214 Members
1961 Online
110115 Solutions
New Discussion

Re: Create file with specific mode

 
hangyu
Regular Advisor

Create file with specific mode

I have created a directory , if I want once everyone create file to it , it will change to a specific mode ( eg. 666 ) right the file is created , is it possible ? thx
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: Create file with specific mode

To get this, everyone must have umask 0.
This may create security issues elsewhere so may not be a good solution.
Court Campbell
Honored Contributor

Re: Create file with specific mode

Since I do not know the specifics I can only say that having a umask of 000 would allow creation of files with perms of 666. I wouldn't advise this. It doesn't make sense to have world readable/writable files. I would think that you would more than likely want to set the sgid bit on the directory and set the group ownership on the directory to a group that all users that would be putting files, etc in that directory are apart of. It's hard to give further advice without knowing more about why files would need to be mode 666 for that directory. Is an application creating the file? is this an ftp directory?
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
hangyu
Regular Advisor

Re: Create file with specific mode

thx Court Campbell,

I also don't want change the umask , it is not safe , you ask why need change the permission to 666 , the reason is : now the umask is 0022 , we have a share folder that everyone(they are different group) need to update the files inside, but now can't , so I would have the request. thx
Dennis Handly
Acclaimed Contributor

Re: Create file with specific mode

If you don't want to use umask, then the users will have to use chmod a+w on their files.

I assume that using ACLs could also be used but may be just as onerous.

If this directory isn't over NFS, you could have a root crontab that does the chmod every so often.

Of course if you own the application that creates the files, you can put the chmod into it.
skt_skt
Honored Contributor

Re: Create file with specific mode

if this directory in question is a static one, you may keep the permission 666 so as to allow every one to create files on it.

You may also try setting sticky bit so that the each users' files wont get removed by the other user.similar to /tmp file system

drwxrwxrwt 26 bin bin 18432 Jul 2 22:35 /tmp
Eric Jacklin
Regular Advisor

Re: Create file with specific mode

i would suggest you can chose twoways mention below


1) Set cron entries so that it will convert the file according to your need

2) Put a script in .profile file so once the
the person load the profile file attributes will get change
Ninad_1
Honored Contributor

Re: Create file with specific mode

Hi,

If I understand correctly, you want files written to a specific directory to have 666 perms, while you do not want the same for any other directories. Its a bit tricky, because you cannot control the program which is writing the file to use 666 to write to a particular dir.
In that case I agree with the solution of scheduling a job through cron to change perm to 666.

Regards,
Ninad
Court Campbell
Honored Contributor

Re: Create file with specific mode

I still think you should create a new group. Then add the users to the group that need to edit files in this directory. Then change the group of the directory to the new group and setgid the directory. When you change the group on the directory you should it with a -R to make it recursive. With this in place any new files created will get the group of the folder and not the group of the user. This way you do not have to create world readable files.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"