Score:0

All files on /var/www/ change ownership to www-data. Can it be avoided?

fr flag

All files on /var/www/ change ownership to www-data. Can it be avoided?

I have different files with different owners, starting from the /var/www/* directory. But once a day they change and appear as owner and group www-data.

I can't see why this happens. How can I disable this automatic change?

in flag
If something is automatically changing the ownership of the files, then you have likely configured something to do this. Apache (and Ubuntu) will not do this by default. Check if you have a cron job changing ownership. If you have a custom web application, ensure that it is not running as the super user and changing ownership
Dok Gus avatar
fr flag
Thank , Sorry I just saw this answer, Check everything, there is no crontab, do not set anything that makes that change. I did not make script that does. I still don't understand why that happens.
Dok Gus avatar
fr flag
Check everything, you were right, there was a badly set script. Thanks His statement that by default he could not change the ownership of the files was important.
Score:3
cn flag

I have different files with different owners, starting from the /var/www/* directory.

Files in /var/www/ need to be set to the user you use apache with. Otherwise you can run into permission issues and a website with potential security issues.

www-data was the default user for apache (v1). Nowadays apache (v2) uses apache as user and group. See your apache config on what user you use.

To change:

sudo vi /etc/apache2/apache2.conf

find the 2 lines (assuming your www-data as now set):

user www-data
group www-data

If you only want to change it to the user and group you use you can reset your data with this command (After changing user or group you also need to do this):

sudo chown --recursive {user}:{group} /var/www/

change {user} and {group} to what is in the configuration file and restart apache

sudo systemctl restart apache2 

Generic other pointers:

Permissions on files and directories should be at the most this:

sudo chmod 755 /var/    
sudo chmod 755 /var/www/
sudo find /var/www/ -type d -exec chmod 755 {} \;
sudo find /var/www/ -type f -exec chmod 644 {} \;    ]
  • "0" means nothing; "7" is read, write, and execute; "6" is read, write. The "d" means directories, the "f" means files.
  • Don't put executable files in /var/www/. Use a dedicated directory (apache has a cgi-bin option for this).
  • If possible set "others" to "0".
  • If possible set "group" to "0" as well; group is only needed if there are 2 or more users altering files on the server
  • If setting one of them to "0" and it yields permissions errors you have a mistake in a settings file for that specific software and should fix that setting instead of altering permissions.
Dok Gus avatar
fr flag
Thanks. For security reasons, it is better that all the files are under the domain of www-data (ubuntu server www-data owner of the apache files). I have a directories with scripts, I just want property of another user. It is easy if with the comnado chown change of owner. But in less than 24 hours the files belong to www-data again. I can't know why it changes ownership. There is a way to deactivate that automatic change I insist with the chown command I revert the change but it introduces a change date in the file that complicates the backup. From already thank you very much
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.