This is a question that I have seen several discussions about, but am still not sure what the best solution is:
What is the best way to set up users and groups for web folders?
For the sake of this discussion: *I use Ubuntu and Apache *My web-folder is /var/www/mydomain.com *Apache default user is www-data and www-data group *my user is me, adam
Currently, I do this:
add my user to www-data group with:
sudo usermod -aG www-data $USER
and then I just add a symlink for www to my users home folder with:
ln -s /var/www ~/
Now when I sftp into my users home-folder, I can just click through to www and I have enough permissions to edit files and such. If I create new files, I have to remember to run:
sudo chown -R www-data:www-data /var/www
Doing that sets the new files to be owned by www-data. Everything works and the internet is happy.
I have been thinking of trying something a little different. What if I set www-data as the default group for adam.
sudo useradd adam -g www-data
And then set adam as the owner of /var/www and www-data as the group
sudo chown -R adam:www-data /var/www
In theory, Apache user www-data will still be able to do its thing, but adam will be the owner, and when I log in as adam I can create new files without having to worry about updating permissions all the time.
Anyone have a better way of handling users? Thoughts on my approach?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.