LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   files to inherit all permissions from parent folder (https://www.linuxquestions.org/questions/linux-newbie-8/files-to-inherit-all-permissions-from-parent-folder-4175648113/)

aristosv 02-12-2019 12:17 AM

files to inherit all permissions from parent folder
 
I create a folder and a file inside that folder. Then I make www-data the owner of that folder and all containing files.

Then I run "chmod g+s /var/www/html/testdomain.com" so any new files created under that folder, get the same permissions.

But when I create a new file under that folder, I can see that root still has permissions on it, not www-data.

How can I make it so that file "2" has the same permissions as file "1"?

Code:

root@webserver:/var/www/html# mkdir testdomain.com
root@webserver:/var/www/html# cd testdomain.com/
root@webserver:/var/www/html/testdomain.com# touch 1
root@webserver:/var/www/html/testdomain.com# ls -l
total 0
-rw-r--r-- 1 root root 0 Feb 12 08:07 1
root@webserver:/var/www/html/testdomain.com# chown -R www-data:www-data /var/www/html/testdomain.com
root@webserver:/var/www/html/testdomain.com# ls -l
total 0
-rw-r--r-- 1 www-data www-data 0 Feb 12 08:07 1
root@webserver:/var/www/html/testdomain.com# chmod g+s /var/www/html/testdomain.com
root@webserver:/var/www/html/testdomain.com# touch 2
root@webserver:/var/www/html/testdomain.com# ls -l
total 0
-rw-r--r-- 1 www-data www-data 0 Feb 12 08:07 1
-rw-r--r-- 1 root    www-data 0 Feb 12 08:09 2
root@webserver:/var/www/html/testdomain.com#


Brains 02-12-2019 01:40 AM

All files and directories are "owned" by the person who created them. You created "2" from a root prompt, root is the owner.
To answer your question: chown www-data 2

ondoho 02-12-2019 02:08 AM

Quote:

Originally Posted by aristosv (Post 5960854)
chmod g+s /var/www/html/testdomain.com
...
Code:

-rw-r--r-- 1 root    www-data 0 Feb 12 08:09 2

the g in your chmod command implies that you do something to group permissions only; that seems reflected in your ls output.
how about just chmod +s /var/www/html/testdomain.com???

aristosv 02-12-2019 02:17 AM

I apologize, reading my original post, perhaps I didn't explain clearly what I'm trying to achieve.

I need all future files and folders created under "/var/www/html/testdomain.com" to have the same permissions as file "1". No matter which user created them.
So any file/folder created under "/var/www/html/testdomain.com" should inherit it's permissions, which are "www-data www-data"

Turbocapitalist 02-12-2019 02:26 AM

The EXT file systems are very weak in this area. So you'll probably want to delve into ACLs instead. ACLs are more complicated but are more powerful in forcing defaults. There is very, very little written about them, however. I mention them briefly with an example at the end of a blog post about directory permissions.

See:

Code:

man getfacl
man setfacl
man 5 acl

But the owner is always going to be the owner unless you have an incron or cron job change that manually.

Brains 02-12-2019 02:45 AM

Your best bet is to install inotify-tools, then add a command to /etc/profile for system wide application to monitor the directory and chown automatically every time a new file or directory is added.
For a specific user only, the command can be added to the user's .bash_profile
For the command to run every boot, it can be added to /etc/rc.local,/etc/rc.d/ or /etc/init.d/ depending on which Linux you are using

EDIT: After installing inotify-tools, look at the manpage for inotifywait, or Google for examples of how to use it

DarrenDrapkin 02-12-2019 06:20 AM

May I suggest that you will have an easier time of it if you look up chown, chmod and umask

scasey 02-12-2019 11:12 AM

chmod g+s only does what you're asking for the group.
Set for users with
Code:

chmod u+s /var/www/html/testdomain.com
From man chmod
Quote:

chmod preserves a directory's set-user-ID and set-group-ID bits unless you explicitly specify otherwise. You can set or clear the bits with symbolic modes like u+s and g-s, and you can set (but not clear) the bits with a numeric mode.
Edit: Sorry, I should have tested before I posted...u+s does not appear to do what you want.

Have you considered simply managing the files as the user that needs to own them? Note that as long as the files are other readable, the apache user does NOT need to be the owner of the files.

The only time the apache user needs write capability to a directory is when some script being run by the apache user is creating output. In those cases, we just make the apache user the owner of the directory.

aristosv 02-12-2019 11:29 AM

I guess as long as the hosted website is managed only from it's web interface, any newly created files should have the correct permissions. I only wanted to do this, in case someone logs in as root, and starts editing/adding files in /var/www/html/testdomain.com

scasey 02-12-2019 11:35 AM

Quote:

Originally Posted by aristosv (Post 5961069)
I guess as long as the hosted website is managed only from it's web interface, any newly created files should have the correct permissions. I only wanted to do this, in case someone logs in as root, and starts editing/adding files in /var/www/html/testdomain.com

If someone logs in as root, they should know they need to update permissions...shouldn't they?

In my experience, it's very unusual for site content to be owned by the apache user. Even WordPress only requires that for a limited set of directories and files.
Files I might create as root via sftp still get served just fine...as long as they are world readable.


All times are GMT -5. The time now is 05:27 AM.