Force Create Permissions

Is there a way to enforce that a file created on a directory will inherit the owner/groupship of the his parent folder?

There is a proccess running as root (I now this is not the good thing to do, but is the way is running now, and it can't be changed in some months) that create tons of files in a folder. i have to sync this files with a twin folder on other machine, but there is no root access by ssh between the 2 machines.

Also, in the twin machine, the process is running with limited user (the right thing), so while I can not change this process to run as root on original machine, I want the files it creates have the folder permissions, and not his.

Solution:

If you mean with, say, the cp utility then yes you can use the --preserve option; e.g.,

Code:

cp --preserve=all file directorySee the man page.

If you can read the files from the other machine (with, say, scp) and have your umask set properly, the files should copy with "your" owner and group; that is, whatever user account is doing the copying will be the owner and group of the copied files and the files will have permission defined by your system umask setting (which probably ought to be 0022 which creates files 0644 and directories 0755).

If the the directory has the setgid bit set then files created in it will have group ownership of the directory. You can set it like this:

Code:

$ mkdir directory
$ ls -ld directory
drwx------ 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory
$ chmod g+s directory
$ ls -ld directory
drwx--S--- 2 lwasserm lwasserm 4096 2009-11-21 11:04 directory

When you see the 'S' in the group permissions field it is set correctly for this behaviour.

Just a note, I believe files "moved" into the directory, rather than created in it, will retain their original group.

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.