Sample Header Ad - 728x90

How to change the owner and group of a directory by the name of that directory?

0 votes
1 answer
2694 views
I have a Ubuntu 16.04 Nginx server environment with several CMS (WordPress) websites under document root. All the site directories have www-data as owner and group, recursively. --- According to some security consultation I got, this is problematic because data from one site could alter any other adjacent site (for example, a malicious module installed in one the CMSs of one of the sites). I assume that the solution would be to change this command which I always run after adding a new site (and also in cron after updates that change owner and group): chown -R www-data:www-data /var/www/html/* To some conditional command that changes these characteristics not just to www-data but to the actual name of the site dir. To clarify, the owner of each site dir should be domain.tld and the group should also be domain.tld (I always name site dirs as per the site's domain.tld). What could be such a conditional command? --- Note: The Nginx user as well as the dir /var/www/html/ will both stay with www-data:www-data. ## Update for G-Man: I have yet to test but I think this is good if you pass ${domain} as the first argument for a variable ($1): chown -R ${domain}:${domain} ${domain}/* Though I'd keep it: chown -R ${domain}:www-data ${domain}/* Of course, adduser ${domain} --disabled-password --disabled-login is needed before, if wasn't done.
Asked by Arcticooling (1 rep)
Jan 15, 2018, 05:08 PM
Last activity: Jan 16, 2018, 10:59 PM