I have a folder: /home/myuser/folderA
I want to give the www-data user write access to the above, while 'myuser' continues to have normal access (as it is myuser's home folder anyway).
Which commands do I need to use?
Note: I don't want www-data
to have access to any other folders in /home/myuser/
.
Thanks in advance.
First, add yourself into the group
www-data
Then:
Should do the trick unless the permissions on your
/home/myuser
do not permit other users access.The first command changes the group ownership of the folder to that of the webserver. The second command gives members of the
www-data
group read, write, enter-directory rights, and the groups
flag will ensure that any files that get created inside that directory takewww-data
as the group - so if you create a file asmyuser
thewww-data
user will have access.Nb. this also depends on the
umask
settings of both your user account and the webserver: you need to make sure that files created in folderA have grouprw
access (and directories created within need grouprwx
)If your webserver does not have enter rights into your
/home/myuser
dir (quite sensible) then it's not going to get in there unless you do something else. Two solns:sudo mount --bind /home/myuser/folderA /var/www/mysite/folderA
(this is an ugly hack and would have to be repeated after reboot. But a powerful trick, also can be used to make folders accessible inside SSH jails.)Simply move the shared folder somewhere else, e.g.
/home/shared-stuff/folderA
.The 2nd option is nicest. Let's say the stuff in folderA is really public and you don't care who sees it, you can set it up like
Then you can put inside that, say, folderA with permissions as above, and folderB that www-data should not have access to with different permissions, e.g.
Another way is to change the username directly in apache config, this is if it's your local machine and you save images from somewhere else that would crush any permissions made on the folder. Also to do if you have only 1 user and don't care about www-data!
Find User and Group and put yours
User <Your User>
Group <Your Group>