Score:0

allow access to www-data to files in user's home dir

cn flag

I have 2 users with the following home directories:

  • user1 --> /srv/user1
  • user2 --> /srv/user2

Problem is: I want these home folders to be accessible online via apache2 but accessible to the users as well . If I set the owner of each home directory to the corresponding user, I can ftp to these directories, but apache fails to access the files. If I set owner to www-data, the directories work fine with apache, but the users can't read their own home directories.

If I add user1 and user2 to www-data group and give +rw to the entire group, this will make user 1 able to read user 2's files (and vice-versa), and I want each user to read his own files only.

How can I achieve this?

Thanks in advance

cn flag
I don't have the time right now to look into this in detail, but [per-user web directories](https://httpd.apache.org/docs/2.4/howto/public_html.html) might be of interest.
user206904 avatar
cn flag
@HenningKockerbeck thanks the link. I heard about the userdir module, but thought it might be an overkill for my use-case (only 2 users have web folders, the others are just local users). I might give it a try in the future if needed, but the trick in the marked answer worked fine for now.
Score:1
gb flag

I think what you want is the other way round. Provide the www-data account access to the user files:

usermod -a -G users www-data
user206904 avatar
cn flag
this does the job for me. I just had to make sure some files outside the web folder don't have rw for group and it worked fine. Thanks
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.