Centos – How to make the user the owner of new files

centospermissions

I have VPS with CentOS 5.4.

This is production server.

The problem is when my webiste installs some scripts from site , then the owner name is not written on the file and as user i can even change the file permissions.

Is there any way that which ever script is writing file , the owner of home directory should the owner of all the files

Best Answer

Note: this solution requires changing permissions for file creation for specific users and directories.

Setting the setgid permission bit on a directory that will be written into will keep all new files written in that directory assigned to the group of that directory (instead of to the group of the user that created them).

If the HTTP server's user creates files with group write permissions by default, then all files written into directories in the proper user group and with the setgit bit set will be fully accessibly by the users in that group.

Setting the setgid bit on directoryname setting proper group ownership:

chmod g+s directoryname
chown :groupname directoryname

If group-write permission is not set by default, you'll need to set the umask of HTTP server user.