LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-12-2019, 01:17 AM   #1
aristosv
Member
 
Registered: Dec 2014
Posts: 167

Rep: Reputation: 3
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#
 
Old 02-12-2019, 02:40 AM   #2
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 825

Rep: Reputation: 204Reputation: 204Reputation: 204
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
 
Old 02-12-2019, 03:08 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 10,790
Blog Entries: 7

Rep: Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708
Quote:
Originally Posted by aristosv View Post
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???
 
Old 02-12-2019, 03:17 AM   #4
aristosv
Member
 
Registered: Dec 2014
Posts: 167

Original Poster
Rep: Reputation: 3
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"
 
Old 02-12-2019, 03:26 AM   #5
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 3,689
Blog Entries: 3

Rep: Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651Reputation: 1651
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.

Last edited by Turbocapitalist; 02-12-2019 at 03:27 AM.
 
Old 02-12-2019, 03:45 AM   #6
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 825

Rep: Reputation: 204Reputation: 204Reputation: 204
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

Last edited by Brains; 02-12-2019 at 03:54 AM.
 
Old 02-12-2019, 07:20 AM   #7
DarrenDrapkin
Member
 
Registered: Aug 2014
Location: Leeds, England
Distribution: Slackware x86 64 current
Posts: 76

Rep: Reputation: 16
May I suggest that you will have an easier time of it if you look up chown, chmod and umask
 
Old 02-12-2019, 12:12 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 2,415

Rep: Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798
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.

Last edited by scasey; 02-12-2019 at 12:19 PM.
 
Old 02-12-2019, 12:29 PM   #9
aristosv
Member
 
Registered: Dec 2014
Posts: 167

Original Poster
Rep: Reputation: 3
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
 
Old 02-12-2019, 12:35 PM   #10
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.5
Posts: 2,415

Rep: Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798Reputation: 798
Quote:
Originally Posted by aristosv View Post
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.

Last edited by scasey; 02-12-2019 at 12:36 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inherit permissions from parent folder Axel van Moorsel Linux - Server 1 02-26-2014 02:22 PM
How to set file ownership to inherit its parent folder? pauloray Linux - Virtualization and Cloud 2 01-15-2012 07:54 PM
[SOLVED] Can not inherit the permission from parent folder to child. Toushi Linux - General 4 04-28-2011 07:15 AM
[SOLVED] C++ classes - a matter of style? inherit or not inherit? worzel1968 Programming 25 03-21-2011 03:40 PM
automatically inherit parent folder permissions when copying files teixeira Linux - Newbie 3 07-08-2008 01:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration